how to customize devise error messages with classes

后端 未结 4 734
温柔的废话
温柔的废话 2021-02-08 16:06

im using twitters bootstrap alert messages. in my application.html.erb I have...

            <% flash.each do |key, value| %>
                
4条回答
  •  梦谈多话
    2021-02-08 16:36

    The simplest solution I've found is to use a common partial for all flash messages while checking for :notice and :alert to replace with the necessary bootstrap class.

    So make /views/shared/_alerts.html.erb like this -

    <% flash.each do |message_type, message| %>
     
    <%= message %>
    <% end %>

    Add a helper method (I've added it to the application helper) like this -

    def flash_class_name(name)
      case name
      when "notice" then "success"
      when "alert"  then "danger"
      else name
      end
    end
    

    Include _alerts.html.erb in the application layout (or the parent layout for your application).

    That's it!

提交回复
热议问题