Alex Rivera | Logout

Rails: How to change the title of a page?

Asked 2008-10-09T04:53:04.927
175

What is the best way to create a custom title for pages in a Rails app without using a plug-in?

Edit
Report

2 Answers

24

An improvement on @opsb and a more complete form of @FouZ's:

In application.html.erb:

<title><%= @title || "Default Page Title" %></title>

In the view erb file or its controller:

<% @title = "Unique Page Title" %>
answered 2013-05-19T17:48:38.570
4

I use nifty_generator's "nifty_layout" which provides with a title variable which I can call then on the page using:

<% title "Title of page" %>

I can also user <% title "Title of page", false %> to have the title just show in browser title and not in the page itself.

answered 2010-09-26T03:07:07.687

Your Answer