Rails - How can I detect if the content_for content was provided?

Posted by sa125 on Stack Overflow See other posts from Stack Overflow or by sa125
Published on 2010-04-25T08:07:37Z Indexed on 2010/04/25 8:13 UTC
Read the original article Hit count: 453

Filed under:
|
|

Hi - I want to detect if content was provided for content_for tag in my template, and if not fall back to default value:

<title>
  <% if content_is_provided -%>
    <%= yield :title -%>
  <% else -%>
    404 - Page Unknown
  <% end -%>
</title>

Any easy way to detect this? I tried <% if :title -%> but that didn't do much. thanks.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about erb