Metamagic is a simple Ruby on Rails plugin for creating meta tags.
In your Gemfile:
gem 'metamagic'
Then run bundle install
.
In your app/views/layouts/application.html.erb:
<head>
<%= metamagic %>
...
</head>
Then, at the top of your view, e.g. app/views/posts/show.html.erb:
<%
meta :title => "My title",
:description => "My description",
:keywords => %w(keyword1 keyword2 keyword3)
%>
This will generate the following:
<head>
<title>My title</title>
<meta content="My description" name="description" />
<meta content="keyword1, keyword2, keyword3" name="keywords" />
...
</head>
It's possible to specify default values to be shown if a view doesn't specify its own values. In your app/views/layouts/application.html.erb:
<head>
<%= metamagic :title => "My default title", :description => "My default description.", :keywords => %w(keyword1 keyword2 keyword3) %>
...
</head>
These values are then inserted if a view doesn't set others.
For custom meta tags, just call it like this in the top of your view:
<%
meta :my_custom_tag => "My custom value"
%>
This will generate the following:
<head>
...
<meta content="My custom value" name="my_custom_tag" />
...
</head>
With custom properties:
<%
meta [:property => "og:image", :content => "http://mydomain.com/images/my_image.jpg"]
%>
This will generate the following:
<head>
...
<meta content="http://mydomain.com/images/my_image.jpg" property="og:image" />
...
</head>
Follows semantic versioning.
Copyright (c) 2010-2013 Lasse Bunk, released under the MIT license