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

Metamagic: Ruby on Rails meta tags plugin

Ruby on Rails plugin for creating meta tags.

I have created a plugin named Metamagic that enables you to easily create meta tags for your Ruby on Rails site.

In your controller:

def show
  @product = Product.find(params[:id])

  meta :title => @product.name, :description => @product.description, :keywords => @product.tag_list
end

In your application.html.erb:

<head>
  <title>My Site</title>
  ...
  <%= metamagic :title => "My default title", :description => "My default description.", :keywords => %w(keyword1 keyword2 keyword3) %>
  ...
</head>

For custom meta tags, just call it like this in your controller:

meta :title => "My title", :my_custom_tag => "My custom value"

More information and docs at GitHub.

Related posts

Tags: , ,

3 comments

  1. Bill Eisenhauer says:

    Unless I’m missing something, the tag method is not a part of this plugin, but is required. Could it be that this is a method from an application that you harvested this plugin from?

  2. Bill Eisenhauer says:

    Okay, nevermind. Seems like this plugin would be more useful if strictly included in views rather than controllers. In Rails 3, the tag method is only available in ActionView, so I did this:

    ActionView::Base.send :include, Metamagic::HelperMethods

    and then removed the included method. Seems like this should be an optional usage method that the plugin should automatically support.

  3. lassebunk says:

    Hi Bill,

    I’m not sure I fully understand what you mean – could you explain further?

    /Lasse

Leave a comment

Fork me on GitHub