简体   繁体   中英

Devise error messages for sign in

As known Devise uses flash for alerts when sign in process is failed. There is no resource.errors array, just flashes. So my question is how it do this? I mean how can I use this feature for my purposes? Is there stock Devise's helper or controller method for moving resource errors from resource.errors to flash? Or only way is to write my own implementation?

I tried to figure out it by myself, but I failed.

Thanks.

Devise uses I18N for it's flash messages, which allows you to fully customize them, or even add your own. Have a look at config/locales/devise.en.yml inside of your project directory. In there you will see all of the English translations needed for Devise's flash messages.

If you look at the SessionsController in Devise you will see the following line:

set_flash_message(:notice, :signed_in) if is_navigational_format?

This calls their set_flash_message and passes in the flash type and the translation needed.

As for wanting to use this for your purposes, it really depends on what you are wanting to do. Translating it to a new language is as simple as adding the YAML file under locales, such as config/locales/devise.es.yml for Spanish, then translating the existing text.

Anything beyond that, such as adding new flash messages, would require overriding the default Devise controllers, which examples of can be found in their wiki , or by a simple Google search

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM