Rails 3: yield/content_for with some default value?

Is there any way to detect if #content_for was actually applied to a yield scope in Rails?

A classic example being something like:

<title><%= yield :page_title %></title>

If a template doesn't set that with

<% content_for :page_title, "Something here" %>

Is there a way to have the layout put something else there instead?

I tried defining it with #content_for in the layout itself, but this just causes the text to be doubled-up. I also tried:

<%= (yield :page_title) or default_page_title %>

Where #default_page_title is a view helper.

This just left the block completely empty.

59
задан d11wtq 7 May 2011 в 16:06
поделиться