how to customize devise error messages with classes

后端 未结 4 667
温柔的废话
温柔的废话 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:46

    For anyone coming across this that does not know how to override the devise error messages with bootstrap.

    1. Create file named:

    /app/helpers/devise_helper.rb

    1. Add the following code:
    module DeviseHelper
     def devise_error_messages!
      return '' if resource.errors.empty?
    
       messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
       sentence = I18n.t('errors.messages.not_saved',
       count: resource.errors.count,
       resource: resource.class.model_name.human.downcase)
    
       html = <<-HTML
       

    #{sentence}

    #{messages}
    HTML html.html_safe end end

提交回复
热议问题