I have a simple yield use case and for some unknown reason the default case is never shown:
In my super_admin layout I have:
<%= yield :body_id || \'s
I know this is an old question but I have a solution for Rails 2.3.
I've extended shingara's yield_or helper method above so it can now accept a block:
module ApplicationHelper
def yield_or(name, content = nil, &block)
ivar = "@content_for_#{name}"
if instance_variable_defined?(ivar)
content = instance_variable_get(ivar)
else
content = block_given? ? capture(&block) : content
end
block_given? ? concat(content) : content
end
end
and this can be used in your templates:
<% yield_or :something do %>
something else
<% end %>
or
<%= yield_or :something, 'something else' %>