我想在Rails应用程序消息上有一个关闭按钮。
我读过有关将Rails Flash消息与Twitter Bootstrap集成的信息,但我遇到了麻烦。
这种消息是引导警报。查看引导程序文档,并确保已将您的应用程序与引导程序集成在一起。
为了将Flash消息与Bootstrap集成在一起,我建议您遵循以下方法:
创建局部 _flash_messages.html.erb
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
然后在您的application.html.erb
添加:
<%= render partial: "shared/flash_messages", flash: flash %>
在您的application_helper.rb
:
module ApplicationHelper
def bootstrap_class_for flash_type
case flash_type
when :success
"alert-success"
when :error
"alert-error"
when :alert
"alert-block"
when :notice
"alert-info"
else
flash_type.to_s
end
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句