How to fix form errors on the login page using Devise

I use Devise for authentication, and the sign form uses flash notifications instead of form errors to display any login issues. But I want to highlight the appropriate form fields that are associated with such errors as usually happens in rails forms. Does anyone know how to do this?

+4
source share
3 answers

By default, the Devise errors function for development 1.1.5 can be found in self-education:

invent-1.1.5 / application / helpers / 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 sentence = "#{pluralize(resource.errors.count, "error")} prohibited this #{resource_name} from being saved:" html = <<-HTML <div id="error_explanation"> <h2>#{sentence}</h2> <ul>#{messages}</ul> </div> HTML html.html_safe end end 

I assume that you can rewrite this module / function if you want it to behave differently.

+1
source

Depending on the version of Rails (up to 3 or not) you can use:

 <%= f.error_messages_for :model %> 

Rails versions prior to 3.0 use this code to handle and format errors. In Rails 3, this method has become obsolete. You need to install this plugin to use the erb code above.

You can read more about this change under the "New Features" chapter of this asciicast.

This tutorial covers the entire process of creating an authentication system based on development and cancan.

0
source

Errors are saved on the map:

 resource.errors 

If your form field is called :email , you may receive an error related to this:

 resource.errors[:email] 
0
source

All Articles