我想在设计中设置根路径后设置这是我在应用程序控制器中的代码
def signed_in_root_path(scope_or_resource)
if current_user.role == "dealer"
dashboard_dealer_path
elsif current_user.role == "admin"
admin_dashboard_path
else
dashboard_customer_path
end
end
登录后,我永远不能返回到routes.rb文件
中的根页面devise_scope :user do
root :to => 'carinfos#index'
end
登录后我可以进入carinfos /索引页面(即,我不应该看到localhost:3000),当我转到该页面时,如果以经销商身份登录,我应该被重定向到经销商仪表板
答案 0 :(得分:1)
在设计会话控制器中有一个名为after_sign_in_path_for
的方法def after_sign_in_path_for(resource)
if resource.role == "dealer"
dashboard_dealer_path
elsif resource.role == "admin"
admin_dashboard_path
else
dashboard_customer_path
end
end
只需覆盖会话控制器
class SessionsController < Devise::SessionsController