1
我正在使用Bootstrap进入我的页面,并且遇到了Flash错误的问题。我需要所有闪光灯获得Bootstrap风格,所以我制作了一个辅助模块来做到这一点。 Flash通知适用于风格,但是当我强制出现错误时,它只是在没有风格的情况下出现“级别不能为空”。 Tnis是我的代码:将Bootstrap样式应用于Flash错误
_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_helper.rb
module ApplicationHelper
def bootstrap_class_for flash_type
if flash_type == "success"
"alert-success"
elsif flash_type == "error"
"alert-error"
elsif flash_type == "alert"
"alert-block"
elsif flash_type == "notice"
"alert-info"
else
flash_type.to_s
end
end
末
_form.html.erb
<% if @control.errors.any? %>
<div class="alert alert-error fade in">
<% @control.errors.full_messages.each do |error_message| %>
<p><%= error_message %></p>
</div>
<% end %>
<% end %>
好,不过我使用的轨道,我不会写代码,而不大成。我想知道,如果我需要我在_form.html.erb中写的代码,或者如果它足够使用flash.each,那么...... – 2014-12-04 09:13:05
:)我也使用Rails。 Slim是一个Rails'gem。它允许编写更少的html。 (http://slim-lang.com)。 – 2014-12-04 20:16:46
谢谢你,我会看看它 – 2014-12-04 22:56:27