Rails 3: yield/content_for with some default value?

You can use content_for? to check if there is content with a specific name:

<% if content_for?(:page_title) %>
  <%= yield(:page_title) %>
<% else %>
  <%= default_page_title %>
<% end %>

or

<%= content_for?(:page_title) ? yield(:page_title) : default_page_title %>

Then in your views you can specify the content like

<% content_for :page_title do %>
    Awesome page
<% end %>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)