Tuesday, 6 March 2012

Ruby on Rails Page Titles

Accurate page titles are an important part of the SEO for any website. However the architecture of a modern web application relies on the content for each individual page being surrounded by a single layout to help keep the overall layout easy to maintain.

This can have a detrimental effect on SEO as Google (and the others) don’t approve of repetition of page titles as it doesn’t provide helpful information to your users. 

The Rails Approach to Page titles

Let’s setup your app so you can have custom page titles and a fall back title for those you forget.
First in your application.html.erb file (or the page you are using for the layout) add this line of text:

<title><%= content_for?(:title) ? content_for(:title) : "Beo | London based results driven web design & development" %></title>

Here are the standard <title> tags for your website with a dynamic bit of code in-between. The code looks to see if you have a custom title and if not displays the default page title (but remember this is something we are trying to avoid!).  

Next we need to add in the method referenced above, in your application_helper.rb file add this:

def title(page_title)
  content_for(:title) { page_title }

Now we need to go to each of our individual pages and insert a line of code, for example on our services.html.erb page we have:

<%- title "Beo | London based results driven web design & development | Services" %>

Again, it’s pretty simple, the code passes the hard coded title to the helper which in turn passes it to the application layout.

Go through each of your pages adding in some custom text for each title.

SEO tips from www.beo.so

Thursday, 23 February 2012

Great design = Great websites?

Yes and no.

A recent Ski holiday to the Alps proved and long held belief of mine on what makes a truly great website.

Take a look at the two websites below:


(Click to enlarge)

(Click to enlarge)

Which do you think is the best designed website? Many of you would no doubt go for B.
Now let me ask you which you think I found the most helpful during my holiday and which website I came back to for information. The answer is A.

Why A?

A isn’t particularly well designed, boring some might say, but the reason behind my visit to both websites was to get information on the resort I was visiting. B looked ok but the information was hidden behind menus and flashy graphics, I got annoyed navigating around looking for information I couldn’t find. This is a fatal sin in the web design world, your website is there to serve a purpose, whether that is to pass on information or sell to your customers. If you frustrate your users you will lose them.

The perfect solution?

Is the content of A but with a modern and clean design that works for the user rather than against. That’s the kind of websites we build at Beo.

Monday, 13 February 2012

Keeping Heroku Awake

As an avid fan of Heroku I've used it to host many websites, from very simple ones with a low amount of visits to very complex applications with a large amount of traffic.

However if you are creating your first website with Heroku you may run into a problem. Heroku uses 'Dynos' to run your website, think of them much like a single processor. The more dynos you have the more processing power you have at your disposal. With Heroku you get 1 months worth of a single dyno use for free.

The problem comes when no one has visited  your site for an hour. After an hour your dyno will shut down to save Heroku's resources. If someone then visits your site it will take 5-10 seconds to spool up the dyno and get it serving the users requests. This obviously causes a delay which as us web developers know, any unnecessary delays are unacceptable. Speed matters.

How to get around this?

The best way around this is to keep your Heroku app awake. For this I used the  Heroku scheduler add-on:

This works much like a Cron Jobs but has a few additional features.

First, add Heroku Scheduler to your desired app. Then go to the admin for that application and enter the Heroku Scheduler management area from the 'Add-on' drop down menu

This screen is where we manage what tasks to run and when. I've called this task 'Call_page' as it will be simply calling our heroku app's index page. We will schedule it to run once an hour to keep the app alive.

We now need to add in the code for this task:

Make a new file called 'scheduler.rake' in app/lib/tasks

Within this page put your code:

desc "This task is called by the Heroku cron add-on"
task :call_page => :environment do
   uri = URI.parse('http://www.myapp.org/')

As you can see this is a fairly simple bit of code that simply calls your page.

That's all! Your app will now stay awake.

Is it free? 

Most likely yes, with each Heroku app you receive 450 free hours of dyno time each month. As 1 dyno is always running this will leave you with a few hours of free dyno time each month. Heroku charges $0.05 per hour per dyno pro-rated to the nearest second. As this task takes around 5 seconds of dyno worker time that's 2 minutes per day, 14 minutes a week and 1 hour per month. Easily within your allowance.

Beo is a London based Ruby on Rails development company. Find us at www.beo.so