Reputation: 5755
I added a devise after_sign_in_path_for
method and my flash messages are not appearing. Any idea?
def after_sign_in_path_for(resource)
case current_user.default_role_sym
when :super_admin
flash.now[:notice] = 'Signed in as Super Admin'
root_url
when :company_admin
flash.now[:notice] = 'Signed in as company admin'
root_url
else
msg = "Signed in as ELSE"
flash.now[:notice] = 'Signed in as pending client'
root_url
end
end
Upvotes: 0
Views: 640
Reputation: 52367
Just move the method to application_controller.rb
and you should be good.
Upvotes: 1
Reputation: 1212
After sign in path is called to get the URL to redirect the user to, so after that method is called a 302 redirect is issued from Rails. The browser will make another request to your rails app for the URL that your returned (root_url in this case). flash.now is only available during the current request, after the request complete that flash will be empty. However, if you set flash[:notice] it'll be available on the next request.
Try setting flash[:notice] instead of flash.now[:notice]. See this rails guide for more information.
Upvotes: 2