Currently, there is no dedicated solution for making page titles in
Ruby on Rails. However, there is lots of custom solutions out there. A
The instance variable:
<h1><%= @title = "Hello world" %></h1>
<title>Awesome Site | <%= @title || "Your main source of awesomeness"
The content_for helper:
<h1><% content_for :title, "Hello world" %></h1>
<title>Awesome Site | <%= yield :title || "Your main source of
Besides this, there's also a few people that prefer to set the page
title in the controller. I wouldn't recommend that, though.
I recently posted a ticket on Lighthouse including a patch for Rails
that would allow you to use this syntax:
<h1><%= title "Hello world" %></h1>
<%= title(:site => "Awesome Site") %>
Which will output:
<title>Awesome Site - Hello World</title>
Two configuration options are available:
* reverse, reverses the order of page title and site name. Default is
false, site name first.
* separator, defines the separator of the page title and the site
name. Default is " - ".
More information on the patch here:
Now, my question to you is: Which of the above solutions do you
prefer? If you have a completely different solution I would also like
to hear about it.