Rails check if yield :area is defined in content_for Rails check if yield :area is defined in content_for ruby-on-rails ruby-on-rails

Rails check if yield :area is defined in content_for


@content_for_whatever is deprecated.Use content_for? instead, like this:

<% if content_for?(:whatever) %>  <div><%= yield(:whatever) %></div><% end %>


not really necessary to create a helper method:

<% if @content_for_sidebar %>  <div id="sidebar">    <%= yield :sidebar %>  </div><% end %>

then of course in your view:

<% content_for :sidebar do %>  ...<% end %>

I use this all the time to conditionally go between a one column and two column layout


<%if content_for?(:content)%>  <%= yield(:content) %><%end%>