RailsCasts Pro episodes are now free!

Learn more or hide this

Alex Emelyanov's Profile

GitHub User: holyketzer

Site: http://brainstorage.me/ketzer

Comments by Alex Emelyanov

Avatar

Great idea! Thanks a lot Ryan!!! Before I put header global variable in a controller (((

For layout:

ruby
...
<title>My Site - <%= yield_or_default(:title, "Default title") %></title>
...

and view:

ruby
...
<% title "My page title" %>
...

It doesn't work on rails 3.1.1

ruby
module ApplicationHelper
  def title(page_title)
    content_for (:title) { page_title }
  end

  def yield_or_default(section, default = "")
    content_for?(section) ? yield(section) : default
  end
end

Solve:

ruby
module ApplicationHelper
  def title(page_title)
    content_for (:title) { page_title }
  end

  def yield_or_default(section, default = "")
    content_for?(section) ? content_for(section) : default
  end
end