how to customize devise error messages with classes

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

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

            <% flash.each do |key, value| %>
                
4条回答
  •  -上瘾入骨i
    2021-02-08 16:33

    Thing is that devise_error_messages! by itself wraps the data into div with class='alert', so the form will have 2 nested divs with the same class. Pressing the x button will close nested div, leaving empty div styled as alert. To avoid this you can omit the div inside helper return value as following:

    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
    end
    

提交回复
热议问题