After registration, which needs confirmation, my app redirects to an authenticated page so authentication fails and Devise redirects to the login path.
My flash message after registration is lost because of the second redirect.
Is there somewhere I can add a flash.keep
before redirecting to the login path, in application_controller.rb or in a helper? I'd prefer not to override a devise controller for this if there's an alternative.
After registration, I store a flash message in the session before the redirection to the login path kicks in (because the user is unconfirmed it's "after_inactive_sign_up_path_for()")
Devise Registrations controller:
class RegistrationsController < Devise::RegistrationsController
protected
def after_inactive_sign_up_path_for(resource)
# store message to be displayed after redirection to login screen
session[:registration_flash] = flash[:notice] if flash[:notice]
super
end
end
Then I show this message if it's present during the login request. Devise Sessions controller:
class SessionsController < Devise::SessionsController
def new
flash[:notice] = session.delete(:registration_flash) if session[:registration_flash]
super
end
end
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