I'm trying to redirect user and admin to two different dashboards(admin_dash and user_dash). Started with device gem and set the first user as admin in rails console. Now everything is working perfectly like only admin user can get into admindash board which is created using rails_admin gem.
I created a method for redirection
def admin_user?
current_user && current_user.admin?
end
def after_sign_in_path_for(resource)
if admin_user?
home_admindash_path #error
else
home_userdash_path
end
end
And these are the path get from rails routes
home_admindash GET
/home/admindash(.:format)
home#admindash
home_userdash GET
/home/userdash(.:format)
home#userdash
Here if and else is working correctly based on admin or user but not the path.
ERROR GETTING
NoMethodError in Devise::SessionsController#create
undefined method `user_url' for #<Devise::SessionsController:0x000000000119b8>
CodePudding user response:
I got a right solution, it got worked, and we can refer Devise Redirects to specific page based on User Role on Login
def after_sign_in_path_for(resource)
#binding.pry
if resource.admin == true
home_admindash_path
else
home_userdash_path
end
end
