I'm would like to have a close button on my rails application messages.
I've read about integrating rails flash messages with twitter bootstrap, but I'm stuck.
I'm would like to have a close button on my rails application messages.
I've read about integrating rails flash messages with twitter bootstrap, but I'm stuck.
这种消息是引导警报。检查 bootstrap 文档,并在 rails 中确保您的应用程序与 boottrap 集成。
为了将闪存消息与引导程序集成,我建议您遵循这种方法:
创建一个部分_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