2015-06-01 118 views
1

當前我使用friendlyID寶石,我只是想重新定向我的應用程序到一個根with如果用戶認證。根與slu rails軌道4路由

網址

http://localhost:3000/companyABC/dashboard 

這裏是我當前的代碼

authenticated :employer do 
    root to: redirect("/:slug/dashboard"), as: :employer_root 
    end 

    namespace :company, path: "/:slug" do 
    resources :dashboard 
    namespace :settings do 
     resources :collaborators 
    end 
    end 

但問題是,當我登錄它重定向我 http://localhost:3000/:slug/dashboard

+0

恐怕你需要設置'root'明確。你可以做什麼,是在綁定到根檢查的動作,如果用戶認證,並相應地呈現不同的意見 –

回答

1

據我所知,你不能在路由中使用lambdas,所以訪問數據庫和獲取公司的路由段落是不可能的。

但是,如果您使用設計,您可以覆蓋方法#after_sign_in_path_for,因此用戶將被重定向到root_url而不是指定的url。例如:

class ApplicationController < ActionController::Base 
    def after_sign_in_path_for(user) 
    company_dashboards_url(user.company) 
    end 
end 

點擊此處瞭解詳情:devise docs about after_sign_in_path_for

+0

非常感謝給我一個提示。我想我可以要求在路線上的slu g。 –