Devise - Flash Notices

2020-04-11 13:06发布

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

4条回答
看我几分像从前
2楼-- · 2020-04-11 13:48

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 :-)

查看更多
够拽才男人
3楼-- · 2020-04-11 13:48

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.

查看更多
Melony?
4楼-- · 2020-04-11 13:54

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.

查看更多
别忘想泡老子
5楼-- · 2020-04-11 14:00

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

查看更多
登录 后发表回答