Rails检查是否在content_for中定义了yield:area [英] Rails check if yield :area is defined in content_for
本文介绍了Rails检查是否在content_for中定义了yield:area的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据已定义的实际模板在布局级别进行条件渲染,知道如何完成此工作吗?
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?
推荐答案
@content_for_whatever
已弃用.
改为使用content_for?
,
@content_for_whatever
is deprecated.
Use content_for?
instead, like this:
<% if content_for?(:whatever) %>
<div><%= yield(:whatever) %></div>
<% end %>
这篇关于Rails检查是否在content_for中定义了yield:area的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文