Rails Tutorial Chapter 4 2nd Ed. Title Helper not being called with out argument.
Posted
by
SuddenlyAwakened
on Stack Overflow
See other posts from Stack Overflow
or by SuddenlyAwakened
Published on 2012-06-30T22:31:09Z
Indexed on
2012/07/01
21:16 UTC
Read the original article
Hit count: 252
I am running through the Rails Tutorial by Michael Hartl (Screen Cast). Ran into the and issue in chapter 4 on the title helper.
I have been putting my own twist on the code as I go to make sure I understand it all. However on this one I it is very similar and I am not quite sure why it is acting the way it is.
Here is the code:
Application.html.erb
<!DOCTYPE html>
<html>
<head>
<%- Rails.logger.info("Testing: #{yield(:title)}") %>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
Application_helper.rb
module ApplicationHelper
def full_title(page_title)
full_title = "Ruby on Rails Tutorial App"
full_title += " | #{page_title}" unless page_title.blank?
end
end
Home.html.erb
<h1><%= t(:sample_app) %></h1>
<p>
This is the home page for the <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> sample application
</p>
about.html.erb
<% provide(:title, t(:about_us)) %>
<h1><%= t(:about_us) %></h1>
<p>
The <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> is a project to make a book and screencast to teach web development with <a href="http://railstutorial.org/">Ruby on Rails</a>. This is the sample application for the tutorial.
</p>
What Happens: The code works fine when I set the provide method like on the about page. However when I do not it does not seem to even call the helper. I am assuming that because no title is passed back. Any ideas on what I am doing wrong?
Thank you all for your help.
© Stack Overflow or respective owner