Setting Up meta tags in RoR application For SEO

Meta tags are one of the important aspect for any site. And RoR having the power for clean urls setting up proper meta tags will really do wonders for the site.

So here is the method to setup the meta tags dynamically for all the pages

Here’s what I do (and it’s just one way of many) :

In my layout/application.rhtml

1
2
3 
<%= @meta_title %> My Site Name>
"keywords" content="<%= @meta_keywords %>" />
"description" content="<%= @meta_description %>" />

In my application controller:

1
2
3
4
5
6
7
8 
  before_filter :meta_defaults
  private

 def meta_defaults
    @meta_title = "Welcome to"
    @meta_keywords = "my keywords"
    @meta_description = "my meta description"
  end

and then in individual actions in my controllers I override the defaults

1
2
3
4
5 
def view
    @article = Article.find(params[:id])
    @meta_title = "#{@article.name} - "
    @meta_description = @article.short_description
end

There are many other ways to do it..If there is a better way that you have pls share ur views below.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *