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: Meta tags, Plugins, Ruby on Rails
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?
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.
Hi Bill,
I’m not sure I fully understand what you mean – could you explain further?
/Lasse