在我的应用程序中,我在标题中使用 Bootstrap flash 来显示所有通知/警告。
这是我的代码:
.col-md-8.col-md-offset-2
= bootstrap_flash
.clearfix
.row
= yield
我有一个投票控制器,我想在完全不同的地方,在投票按钮旁边显示警报。
我如何“选择”来显示特定控制器的特定通知?
答案 0 :(得分:1)
这是一种HAML方式。只需用haml复制@David答案。
如果您将布局更改为:
.col-md-8.col-md-offset-2
= bootstrap_flash unless content_for?(:custom_flash)
在您的表单视图中,您输入:
- content_for(:custom_flash) do
= bootstrap_flash
按下按钮:
= yield(:custom_flash)
这样,除非您定义content_for(:custom_flash),否则将显示正常的闪烁
答案 1 :(得分:0)
(我不知道这种花哨的HAML-thingy;))
如果您将布局更改为:
<div class="col-md-8 col-md-offset-2">
<% unless content_for?(:custom_flash) do %>
<%= bootstrap_flash %>
<% end %>
</div>
在您的表单视图中,您输入:
<% content_for(:custom_flash) do %>
<%= bootstrap_flash %>
<% end %>
按下按钮:
<%= yield(:custom_flash) %>
这样,除非您定义content_for(:custom_flash)
,否则将显示正常的闪烁。
我希望你能解决.erb
,或者有人可以帮助我在HAML中做到这一点;)