简体   繁体   English

Ruby on Rails-我可以选择显示特定通知的位置吗

[英]Ruby on Rails - Can I choose where a specific notice will be shown

In my application I am using Bootstrap flash in my header to show all notices/alerts. 在我的应用程序中,我在标题中使用Bootstrap flash来显示所有通知/警告。

Here is my code: 这是我的代码:

.col-md-8.col-md-offset-2
  = bootstrap_flash
.clearfix
.row
  = yield

I have a vote controller that I would like to show its alert in completely different place, next to the vote button itself. 我有一个投票控制器,我想在投票按钮本身旁边的完全不同的位置显示其警报。

How can I "choose" where a specific notice from specific controller will be shown? 如何“选择”显示特定控制器的特定通知的位置?

Here is a HAML way. 这是HAML方式。 Just copying the @David answer with haml. 只需复制带有haml的@David答案。

If you change your layout to: 如果将布局更改为:

.col-md-8.col-md-offset-2
  = bootstrap_flash unless content_for?(:custom_flash)

And in the view for your form you put: 在您的表单视图中,您输入:

- content_for(:custom_flash) do
  = bootstrap_flash

And by the button you do: 通过该按钮,您可以执行以下操作:

= yield(:custom_flash)

This way your normal flashes will be shown unless you define a content_for(:custom_flash) 这样,除非您定义content_for(:custom_flash),否则将显示您的常规闪烁

(I do not know this fancy HAML-thingy ;) ) (我不知道这个花哨的HAML内容;))

If you change your layout to: 如果将布局更改为:

<div class="col-md-8 col-md-offset-2">
  <% unless content_for?(:custom_flash) do %>
    <%= bootstrap_flash %>
  <% end %>
</div>

And in the view for your form you put: 在您的表单视图中,您输入:

<% content_for(:custom_flash) do %>
  <%= bootstrap_flash %>
<% end %>

And by the button you do: 通过该按钮,您可以执行以下操作:

<%= yield(:custom_flash) %>

This way your normal flashes will be shown unless you define a content_for(:custom_flash) . 这样,除非您定义content_for(:custom_flash)否则将显示您的常规闪烁。

I hope you can solve the .erb , or perhaps someone can help me to do it in HAML ;) 我希望您可以解决.erb ,或者有人可以帮助我在HAML中完成它;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM