Using Devise 2.2.4 in Rails 3.2.
When not logged in, and I go to the url myapp.com/documents, Devise redirects me to myapp.com/users/sign_in and displays the flash message configured in devise.en.yml under devise.failure.unauthenticated.
This is desirable!
When not logged in, and I go to the url myapp.com (the root path), Devise redirects similarly and displays the same flash message.
The redirection is still desirable, the flash message not so much.
Is there a way to configure Devise to NOT display the flash 'unauthenticated' message if redirecting from the root path? I know I can get around it in a custom FailureApp, but this would seem to be a common enough case that a simpler resolution should exist.
You can remove the flash message in your SessionsController after the redirect.
class SessionsController < Devise::SessionsController
before_filter :remove_authentication_flash_message_if_root_url_requested
private
def remove_authentication_flash_message_if_root_url_requested
if session[:user_return_to] == root_path and flash[:alert] == I18n.t('devise.failure.unauthenticated')
flash[:alert] = nil
end
end
end
I simply went to devise.en.yml
and removed the unauthenticated
message, leaving it as:
unauthenticated: ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With