Rails 5: content_for和yield不工作



我在application.html.erb中有一个content_for块,如下所示

<% if alert.present? %>
<%content_for :inline_alert_display do%>
<div class="row" data-snackbar>
<%=render 'components/message', {snackbar_class: 'warning', msg:alert}%>
</div>
<%end%>
<% end %>

然后在sessions/new.html.erb中,我调用收益率如下

<%= yield :inline_alert_display if content_for?(:inline_alert_display)%>

为了它的价值,我已经启用了turbolinks

但是没有打印。

可能是我错过了什么,任何帮助解决这个问题将是伟大的,谢谢。

我认为你需要把它颠倒过来,把' yield '放在模板中,把' content_for '放在视图中。

最新更新