Listing 4.2: Defining a full_title helper

In addition to coming equipped with a large number of built-in functions
for use in the views, Rails also allows the creation of new ones. Such
functions are called helpers; to see how to make a custom helper, let’s
start by examining the title line from Listing 4.1:

Ruby on Rails Tutorial Sample App | <%= yield(:title) %>

This relies on the definition of a page title (using provide) in each
view, as in

<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
  This is the home page for the
  <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
  sample application.
</p>

But what if we don’t provide a title? It’s a good convention to have a
base title we use on every page, with an optional page title if we want
to be more specific. We’ve almost achieved that with our current layout,
with one wrinkle: as you can see if you delete the provide call in one
of the views, in the absence of a page-specific title the full title
appears as follows:

Ruby on Rails Tutorial Sample App |

In other words, there’s a suitable base title, but there’s also a
trailing vertical bar character | at the end.

To solve the problem of a missing page title, we’ll define a custom
helper called full_title.