如何在rails 3中为routes.rb设置不同的根路径?我有两种类型的用户叫做admin和普通用户。我需要为用户提供两种不同的根路径。
目前我确实喜欢:
if current_user.admin == true
root :to => 'dashboards#index'
else
root :to => 'companies#index'
end
但是我收到了像
这样的错误未定义的方法current_user
答案 0 :(得分:0)
另一种解决方案就是路由到公司#index then ...
class CompaniesController < ApplicationController
def index
if current_user.admin == true
redirect_to :controller => 'dashboards', :action => 'index'
else
# normal companies index action
end
end
end
您还可以将root引导到通用控制器中的操作,例如SessionsController
,并将控制器重定向到仪表板或公司控制器。那可能更清洁。