Ruby on rails 在根路径中签名后设计
我想在设计中设置登录后的根路径这是我在应用程序控制器中的代码Ruby on rails 在根路径中签名后设计,ruby-on-rails,ruby-on-rails-3,devise,routing,Ruby On Rails,Ruby On Rails 3,Devise,Routing,我想在设计中设置登录后的根路径这是我在应用程序控制器中的代码 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
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
登录后,我可以进入CarInfo/索引页面(即,我不应该看到localhost:3000),当我进入该页面时,如果以经销商身份登录,我应该重定向到经销商仪表板。在Desive session controller中,有一种方法称为
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
class sessioncontroller
我试过了,当我键入localhost:3000时,它并没有将我重定向到localhost:3000/仪表板/经销商。我想我们可以在应用程序控制器本身中进行覆盖,对吗?在它中签名后,正确地重定向到仪表板,如果我键入localhost:3000,它应该重定向到仪表板,如果已登录,那么尝试在应用程序控制器中登录根路径…检查用户是否未登录重定向到登录路径,当用户登录时,再重定向到相应路径在用户登录后正确重定向,但在登录后,他应该无法看到routesif user is dealer中提到的登录页/根页面,然后重定向到dealer path,如果是admin,则重定向到admin path。。。。你想以这种方式重定向,对吗?