Meta-tags gem
A cheatsheet by @rstacruz|Refreshed 7 months ago.Refresh|View source on Github

Titles

Titles

set_meta_tags title: 'Member Login'
# <title>Some Page Title</title>
set_meta_tags site: 'Site Title', title: 'Member Login'
# <title>Site Title | Page Title</title>
set_meta_tags(
  site: 'Site Title',
  title: 'Member Login',
  reverse: true,
  separator: '&middot;'.html_safe
)
# <title>Page Title · Site Title</title>

Works in a controller or a view.

Setting defaults

Setting defaults

rails generate meta_tags:install

This creates config/initializers/meta_tags.rb that you can edit.

Others

Others

set_meta_tags site: 'Site name'
set_meta_tags title: 'Title'
set_meta_tags description: "All text about keywords"
set_meta_tags keywords: %w[abc def ghi]
set_meta_tags canonical: 'http://...'
set_meta_tags icon: 'favicon.ico'
set_meta_tags author: 'http://...'
set_meta_tags alternate: { 'fr' => 'http://...' }
set_meta_tags prev: 'http://...'
set_meta_tags next: 'http://...'
set_meta_tags image_src: 'http://...'
set_meta_tags noindex: true
set_meta_tags nofollow: true
set_meta_tags follow: true
set_meta_tags og: { image: ['...'] }
set_meta_tags twitter: { description: '...' }
set_meta_tags separator: '·'   # Site · Page title
set_meta_tags prefix: ' '      # Around the separator
set_meta_tags suffix: ' '
set_meta_tags lowercase: true  # Lowercase page title
set_meta_tags reverse: true    # Site name last

In views

In views

# Displaying tags
<%= display_meta_tags %>
# Displaying tags individually
<h1><%= title %></h1>
# Setting tags
<% title 'Member Login' %>
<% description 'My page' %>
<% keywords '..' %>
This cheat sheet can be found in the following categories: