如何应用自定义的Bootstrap消息错误来设计?

我正在将Bootstrap3错误样式应用于我的Rails4应用程序中的所有消息,这里( 来源 )

def bootstrap_class_for flash_type { success: "alert-success", error: "alert-error", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s end def flash_messages(opts = {}) capture do flash.each do |msg_type, message| concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' }) concat message end) end nil end end 

在同一时间我试图将相同的样式应用于设计错误消息,但它不起作用。 例如; 在[views / / registration / new]中你看到 它显示没有样式的错误消息。

我如何应用Bootstrap样式(上面)来设计错误消息?

覆盖devise_error_messages! 辅助方法

应用程序/佣工/ devise_helper.rb

 module DeviseHelper def devise_error_messages! return "" if resource.errors.empty? messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join html = <<-HTML 
#{messages}
HTML html.html_safe end

如果设备没有使用任何css类,那么我们使用alert-error类代替你可以使用你的自定义类