Devise - Flash Notices

2020-04-11 13:50发布

问题:

Using rails with Devise, anytime you sign in or signout devise spits a Flash Notice on the page which doesn't seem necessary from a UI perspective, it's usually pretty obvious, right?

Is there a way to turn off flash notices in Devise for Sign In and Sign Outs?

Thanks

回答1:

Just try adding this code in your sessions_controller.rb.

class SessionsController < Devise::SessionsController
  after_action :clear_sign_signout_flash, :only => [:create, :destroy]
protected
  def clear_sign_signout_flash
    if flash.key?(:notice)
      flash.delete(:notice)
    end
  end
end

Hope this helps :-)



回答2:

Devise has one way of customizing this type of behavior: overriding controllers. Open Devise source code, find app/controllers/sessions_controller and copy it to your application. Devise will start using your own controller rather than its own. From there you can easily modify flash messages.



回答3:

You can go to the localization file and customize any flash messages, even if to specify empty strings. Look in the documentation under i8n and you'll see how it's done.



回答4:

This question has the correct and updated Answer: Rails Disable devise flash messages.