1) As far as I understand Sign In failure messages are automatically put in the flash hash while Sign Up failure messages are not. Am I right?
Indeed.
2) If so, what is rationale behind it? I mean, why are Sign In failure messages are automatically added to the flash but Sign Up and Send Me Reset Password are not?
When creating/updating the User model (or the model used for Devise), the error are going to be showed like form errors. Login/Logout doesn't modify the model, so a flash message is shown instead.
Also, (particularly for Sign Up
) showing a big unformatted paragraph with several error messages at the top (where usually the flash messages lie) doesn't seem like a good idea, compared to having a special <div>
just on top of the form having the attributes and errors showed in a pretty format.
3) I want to put all generated Devise messages into the flash so that the partial will display it. So far, the only way I have come up with is to override devise_error_messages! ,scan the resource.errors.full_messages and put them into flash. Does anyone know a better method to do it?
If you still want to use a flash message to show the error messages, the code you're showing only gives you the first error message, not all.
Try something like this:
flash.now[:error] = resource.errors.full_messages.join(" ")
Or even better, since devise_error_messages!
is called from the view for the form:
- remove that call on the view (you'll probably need to generate the views from Devise).
- use
flash[:error] = resource.errors.full_messages.join(" ")
on the Controller.