Rails check if yield :area is defined in content_for

后端 未结 6 1223
我寻月下人不归
我寻月下人不归 2020-12-22 22:23

I want to do a conditional rendering at the layout level based on the actual template has defined content_for(:an__area), any idea how to get this done?

6条回答
  •  無奈伤痛
    2020-12-22 23:02

    not really necessary to create a helper method:

    <% if @content_for_sidebar %>
      
    <% 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

提交回复
热议问题