2013-01-08 55 views
0

我使用設計進行身份驗證,並希望將身份驗證用戶路由到位置#show。用戶屬於某個位置。我試過一對夫婦的事情,包括這路線設計認證路線

authenticated :user do 
    match 'locations/:id' => 'locations#show', :as => :root 
    end 

不幸的是,這並不能改變登錄即使事情和路線回家#指標。我的全路徑文件

authenticated :user do 
    match 'locations/:id' => 'locations#show', :as => :root 
    end 
    root :to => "home#index" 
    resources :locations 
    devise_for :users 
    resources :users 

任何想法關於如何在用戶登錄時讓root顯示位置ID?

+0

爲什麼不將'root'映射到所需的路徑?如果用戶未經身份驗證(並且您在locations_controller中有'before_filter:authenticate_user!'),則它們將被重定向到sign_in頁面。 –

回答

0

我結束了在我的應用程序控制器

def after_sign_in_path_for(resource) 
    if resource.class == User 
     location_path(resource.location) 
    elsif resource.class == Location 
     location_path(resource) 
    end 
    end 

然後我設置這樣的

authenticated :user do 
    devise_for :users do 
     get "/", :to => "devise/sessions#new" 
    end 
    root :to => 'devise/sessions#new' 
    end 
1

通過在終端中運行以下命令,可以查看與設計相關的所有可用路由。

rake routes 
1

我的路線,您可以使用一根帶符號後的第一定義路徑不同的名稱在驗證區塊內如下所示:

authenticated :user do 
    root to: 'locations#show', :as => authenticated_root 
end