Changing devise flash messages from notice to error

devise, ruby-on-rails-3.2

Solution

You can do it with custom failure app. As you can see this flash message is setting right here So you can change it in your custom failure app.

So at first you inherit your failure app from Devise's one:

class CustomFailure < Devise::FailureApp
  def recall
    env["PATH_INFO"]  = attempted_path
    flash.now[:error] = i18n_message(:invalid)
    self.response = recall_app(warden_options[:recall]).call(env)
  end
end

place this file somewhere in your app and say Devise to use it like this (`config/initializers/devise.rb`):

config.warden do |manager|
  manager.failure_app = CustomFailure
end

Problem

I know that you can override the default devise controllers and I did so for the Registrations and Sessions Controller. I know that you can also change the text for the flash messages in devise under locale. However, I am not sure how to change the type of flash message showing for the sessions controller when there is an invalid combination of username and password. The create method looks like ``` def create self.resource = warden.authenticate!(auth_options) set_flash_message(:notice, :signed_in) if is_navigational_format? sign_in(resource_name, resource) respond_with resource, :location => after_sign_in_path_for(resource) end ``` I suspect that the validation is done during the follow call ``` warden.authenticate!(auth_options) ``` But this is where I am not sure how to overwrite that in my app. Also, I think it is a complex override for such a simple use case of changing the color of a flash notice. Any insights would be much appreciated. Thanks! Nick

Original source