【发布时间】:2014-07-18 15:15:02
【问题描述】:
我在让 flash 与 bootstrap_flash helper 一起工作时遇到了困难。 这是我的代码的 sn-p:
application.html.erb
...
<div class="container">
<%= bootstrap_flash %>
<%= yield %>
</div>
...
bootstrap_flash_helper.rb
ALERT_TYPES = [:error, :info, :success, :warning] unless const_defined?(:ALERT_TYPES)
def bootstrap_flash
flash_messages = []
flash.each do |type, message|
# Skip empty messages, e.g. for devise messages set to nothing in a locale file.
next if message.blank?
type = type.to_sym
type = :success if type.to_s == :notice.to_s
type = :error if type.to_s == :alert.to_s
next unless ALERT_TYPES.include?(type)
Array(message).each do |msg|
text = content_tag(:div, content_tag(:button, raw("×"), :class => "close", "data-dismiss" => "alert") + msg.html_safe, :class => "alert fade in alert-#{type}")
flash_messages << text if msg
end
end
flash_messages.join("\n").html_safe
end
end
我在控制器操作中调用 flash[:notice]。
有人可以给我一个提示吗? 谢谢!
【问题讨论】:
-
它在这里崩溃了:def bootstrap_flash flash_messages = [] flash.each do |type, message|接下来如果message.blank?提高
-
确切的错误信息是什么?我认为最后一个
end太多了...
标签: ruby-on-rails twitter-bootstrap ruby-on-rails-4 twitter-bootstrap-3