I am following railscasts to update custom page title and realized that it doesn't work anymore. So, i updated the code as follows based on the comments. I see 'My Services -' if i do not set the title, whereas i expect it to contain default title value set. Any insights please?
In application.html.erb
:
<!DOCTYPE html>
<html>
<%= render 'layouts/head' %>
<!-- <body> included in yield -->
<%= yield %>
<!-- </body> -->
</html>
In _head.html.erb
<head>
<title>My services - <%= yield(:title) %> </title>
</head>
In home.html.erb
[Intentionally not setting title to see default value]
<body></body>
In application_helper.rb
def title(page_title, default="Testing")
content_for(:title) { page_title || default }
end
In application_helper.rb
, I also tried the following solution:
def title(page_title)
content_for(:title) { page_title || default }
end
def yield_for(section, default = "Testing")
content_for?(section) ? yield(section) : default
end
Any insights please?