Ruby on Rails, programming, and SEO
Check out my articles about Ruby on Rails, programming, and SEO. Weekly updates? Subscribe to my feed.

Rails SEO pack: 5 plugins to optimize your site

Five Ruby on Rails plugins and techniques to improve your SEO.

Update August 3, 2013: The article is now updated to feature the new versions of the plugins.

Here I am going to share some insights on getting your Ruby on Rails site to perform better in search engines, popularly called SEO or Search Engine Optimization.

We are going to use these five Rails plugins:

  1. Headliner for titles
  2. Metamagic for meta tags
  3. Gretel for breadcrumbs
  4. FriendlyId for friendly URLs
  5. Dynamic Sitemaps for sitemaps

1. Titles using Headliner

Headliner is a Ruby on Rails plugin for creating titles in a <title> tag. The plugin makes it easy to define your titles without having to define it in several places.

Titles are important in your SEO pack because they tell search engine users what content is in your individual pages.

In your application.html.erb:

<head>
  <%= title :site => "My Awesome Site",
            :separator => "—",
            :reverse => true %>
  ...
</head>

In your view:

<h1><%= title "Contact info" %></h1>

Would generate the following:

<head>
  <title>Contact info — My Awesome Site</title>
  ...
</head>

2. Meta tags using Metamagic

Metamagic is a Ruby on Rails plugin for generating meta tags.

Despite what you may have heard, meta tags are still important in your SEO pack, especially the title and description meta tags which Google uses in addition to the page content to both find and display your site.

In your application.html.erb:

<head>
  <%= metamagic %>
  ...
</head>

In your view:

<% meta :title => "My page title",
        :description => "This is my page description.",
        :keywords => ["one", "two", "three"] %>

Would generate the following:

<head>
  <title>My page title</title>
  <meta name="description" content="This is my page description." />
  <meta name="keywords" content="one, two, three" />
  ...
</head>

3. Breadcrumbs using Gretel

Gretel is a Ruby on Rails plugin for generating breadcrumbs.

Breadcrumbs are important in your SEO pack as they tell both users and search engines the location or “path” to your pages. Google will also often display the breadcrumb instead of the page URL.

In your application.html.erb:

<body>
  ...
  <%= breadcrumbs :pretext => "You are here: ",
                  :separator => "&rsaquo;" %>
  ...
</body>

In config/breadcrumbs.rb:

crumb :root do
  link "Home", root_path
end

crumb :articles do
  link "Articles", articles_path
end

crumb :article do |article|
  link article.title, article_path(article)
  parent :articles
end

In your controller:

def show
  @article = Article.find(params[:id])
end

In your view:

<% breacrumb :article, @article %>

Would generate a breadcrumb path like this:

<div class="breadcrumbs">
  You are here: <a href="/">Home</a> &rsaquo; <a href="/articles">Articles</a> &rsaquo; My Article
</div>

4. Friendly URLs using FriendlyId

FriendlyId is a Ruby on Rails plugin for generating friendly URLs.

Friendly URLs are important in your SEO pack as they tell users and search engines what lies beneath the URL, e.g. /articles/34 becomes /articles/my-awesome-article.

In your model:

class Article < ActiveRecord::Base
  extend FriendlyId
  friendly_id :title, use: :slugged
end

In your controller:

def create
  @article = Article.create(:title => "My awesome article")
  redirect_to article_path(@article) # => /articles/my-awesome-article
end

5. Sitemaps using Dynamic Sitemaps

Dynamic Sitemaps is a Ruby on Rails plugin for generating sitemaps in the sitemaps.org XML format specification.

Sitemaps are important in your SEO pack because they enable search engine crawlers (like Google) to find all of your pages.

In config/sitemap.rb:

host "yourdomain.com"

# Basic sitemap – you can change the name :site as you wish
sitemap :site do
  url root_url, last_mod: Time.now, change_freq: "daily", priority: 1.0
end

# Pings search engines after generation has finished
ping_with "http://#{host}/sitemap.xml"

Would generate a sitemap like this:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://yourdomain.com/</loc>
    <lastmod>2013-07-29T22:35:23+00:00</lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  ...
</urlset>

It will also ping search engines (Google and Bing) to notify them that your sitemap has changed.

Conclusion

I hope this short guide will be of great use when you’re optimizing your page for search engines. If you have further tips or suggestions, please write a comment below.

Follow me on Twitter

Related posts

Tags: , ,

9 comments

  1. Dan says:

    I stumbled upon this blog entry because I was looking for a Rails 3.0 compatible plugin for headlienr, which I swear was not working last time I tried it. I thought you were mistaken to include it, but lo and behold, it’s working fine on my latest 3.x projects. And now I’ve discovered meta-magic and gretel…thanks!

  2. [...] Rails SEO pack: 5 plugins to optimize your site – Five Ruby on Rails plugins and techniques to improve your SEO. [...]

  3. [...] RubyGems which is a kind of packaging for Ruby. For example, you could have plugins for pagination, search engine optimization, or image processing. As of the time of writing, there are over 27,000 RubyGems to be used for [...]

  4. Bala Paranj says:

    Simple solution. Works great on my new site. Thanks.

  5. lassebunk says:

    @Dan: Nice!
    @Bala: Super!

  6. Hello there, You have done a great job. I will certainly digg it and personally suggest to
    my friends. I’m confident they’ll be benefited from this
    web site.

  7. I visited several sites however the audio quality
    for audio songs existing at this site is truly excellent.

  8. lassebunk says:

    Info: I updated the article today to feature the new versions of the plugins.

  9. Neil Mathew says:

    The one thing i missed from the wordpress is the rich collection of SEO settings it had build in. Thank you sharing this info, it would be really helpful for our product.

Leave a comment

 
Fork me on GitHub