I’m following the Rails Tutorial to get started (for the 4000th time) with Ruby on Rails. I’m pretty much racing through the first couple of chapters, as I have already read and typed these quite a lot of times but I just ran into a minor problem which I cannot seem to solve.
In one of the chapters, it is suggested that we create a helper function to make the displaying of page titles more dynamic.
The helper looks like this:
module ApplicationHelper
#return title on per page basis
def title
base_title = "Ruby on Rails Tutorial Sample App"
if @title.nil?
base_title
else
"#{base_title} | #{@title}"
end
end
end
My controller looks like this:
class PagesController < ApplicationController
def home
@title = "Home"
end
# more pages
end
And finally, my application layout file contains the following line:
<title><%= @title %></title>
The books says that it should now "echo" (is this PHP lingo? Tee-hee) the following title:
Ruby on Rails Tutorial Sample App | Home for the homepage. However, it only echoes ‘Home’ as the page title.
Am I overlooking something here? I don’t think I typed any errors or anything; everything looks fairly logical to me, however it won’t work.
Thanks a lot!
Calling @title in your view refers to the variable, not the method. As the variable @title is equal to “Home”, this is what you get. To call the method, you should try something like :