Meta Rails

Gem Version Build Status

Collection of view helpers to improve search engine optimization of Ruby on Rails application by including appropriate meta tags.

Installation

Open your Rails application's Gemfile and add this line:

gem 'meta-rails'

Save Gemfile and execute bundle command to install the gem.

Title

Based on Moz and Google Help guidelines a proper title consist of page title, brand name, and separator between them.

How to use title helper

# Include 'title' helper in the head section of your site
# e.g., ~/app/views/layouts/application.html.erb
<head>
  <%= title %>
</head>

# Utilize 'provide' or 'content for' to store page's title
# e.g., ~/app/views/users/new.html.erb
<% provide(:title, 'Sign up') %>

This code will create HTML <title> element:

<title>Sign up | AwesomeRailsApp</title>

Format of HTML <title> element can be modified by passing options hash to the title helper:

Option Description Default
:identifier Identifier for stored page's title :title
:brand Brand name Rails.application.class.parent_name
:separator Character between title and brand `\
:reverse Switch position of title and brand false

Meta description

Meta description tag provides a short summary of the page.

How to use meta_description helper

# Include 'meta_description' helper in the head section of your site
# e.g., ~/app/views/layouts/application.html.erb
<head>
  <%= meta_description %>
</head>

# Utilize 'provide' or 'content for' to store page's meta description
# e.g., ~/app/views/users/new.html.erb
<% provide(:meta_description, 'Register to manage your account') %>

This code will create HTML <meta> tag:

<meta name="description" content="Register to manage your account" />

Options hash can be passed to meta_description helper:

Option Description Default
:identifier Identifier for stored page's meta description :meta_description

Robots

Robots meta tag can control the behavior of search engine crawling and indexing.

How to use robots helper

# Include 'robots' helper in the head section of your site
# e.g., ~/app/views/layouts/application.html.erb
<head>
  <%= robots %>
</head>

# Utilize 'provide' or 'content for' to store page's robots directives
# e.g., ~/app/views/users/new.html.erb
<% provide(:robots, 'noindex,nofollow') %>

This code will create HTML <meta> tag:

<meta name="robots" content="noindex,nofollow" />

Options hash can be passed to robots helper:

Option Description Default
:identifier Identifier for stored page's robots directives :robots

Please refer to valid indexing & serving directives page for list of valid robots directives.

License

meta-rails © Dmitriy Tarasov. Released under the MIT license.