Getting your meta tags on track

written by Eadz on February 3rd, 2007 @ 06:17 AM

Sick of the lame Rails puns in the headlines yet? Great!

Ok, so this post is a kind of ‘Ask the community’ post. How do you deal with meta tags including page titles? We should all know the ideal for titles is to be unique for each page on the site , but how do you go about this the rails way?

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

In my layout/application.rhtml
1
2
3
<title><%= @meta_title %> My Site Name</title>
<meta name="keywords" content="<%= @meta_keywords %>" />
<meta name="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

I’ve also seen suggestions for using yield and content_for, but to me that is a bit heavy-weight for simple strings. So, what do you do?

Like this article? Subscribe to the SEO on Rails feed.

Comments

  • random8r on 05 Feb 03:02

    I didn't think SE's used Meta-Tags much anymore. There are quite a few links around the web with fairly good evidence and data to support the fact that meta tags are hardly ever used anymore for searches. Links are by far the greatest provider of rank? - Random8r
  • Eadz on 05 Feb 09:48

    Thanks for your comment. I am including the title tag as part of the meta tags, and you are right in respect to meta keywords for the most part. But the meta description can be used in SERPs (Search Engine Results Pages) as the 'snippet' so while the meta description isn't used for ranking a site, it is sill important.

Comments are closed

Options:

Size

Colors