Couple days ago Google published SEO Starter guide. It's a short document but packed with useful information, that every web developer should check out, especially ones new to SEO.
This article will cover on how the developer related tips in that document apply to a Rails web app.
Create unique, accurate page titles
Ideally, you should create a unique title for each page on your site.
So forget about a static value for title tag in your template layout file (ie. views/layouts/application.html.erb). Title tag value must be content related.
Code sample bellow will include setting meta tag for description as well, which is also important part of search engine optimization. Read more about importance and good choices for title and description values in Google SEO Starter guide.
There's a great screencast on how to approach implementing this, presenting couple of options. My preferred way is with content_for.
In some show.html.erb have something like:
<% content_for :title, "Rails SEO Starter Guide" %>
<% content_for :description, "Learn how to apply Google's SEO Starter guide in Rails apps." %>
<h1><= yield :title %></h1>
... and in application.html.erb:
<head>
<title><%= yield(:title) || "ELC Technologies" %></title>
<%= tag(:meta, :name => 'description', :content => yield(:description) || "Global Web Development Agency") %>
</head>
Improve the structure of your URLs
- Use permalink_fu plugin for pretty permalinks. "Default" Rails URLs with numeric IDs (ie. /articles/1705) is a terrible choice for many reasons for pages with content valuable to user.
-
As the site grows, sometimes URLs has to be changed to maintain well structured URLs.
In that case, you must make sure that "old" links are redirected properly, by using 301 moved permanently status.
def old_show redirect_to params.merge(:action => :show), :status => :moved_permanently end
Optimize your use of images
Always set image :alt value for images that can be considered as "content" (ie. not part of design).
<%= image_tag photo.url, :alt => "spider-man" %>
Be aware of rel="nofollow" for links
When would this be useful? If your site has a blog with public commenting turned on, links within those comments could pass your reputation to pages that you may not be comfortable vouching for. Blog comment areas on pages are highly susceptible to comment spam. Nofollowing these user- added links ensures that you're not giving your page's hard-earned reputation to a spammy site.
So make sure you use this if you use auto_link for user generated content such as comments:
<%= auto_link(h(comment.body), :all, :rel => "nofollow") %>
Take advantage of web analytics services
Put the needed javascript code in partial, so that you don't clutter application layout template. Also, you can skip rendering it in development mode since you don't need useless JavaScript code executed on every page refresh while developing.
<%= render(:partial => "layouts/analytics") unless Rails.env == "development" %>
If you're using GoogleAnalytics, you can even use it as an engine for finding out popular content on the site.

Nice post! this is very important to improve accessibility too.