0

我正在使用设计进行身份验证,并希望将经过身份验证的用户路由到位置#show。用户属于一个位置。我已经尝试了几件事,包括在路线中

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

不幸的是,即使登录也不会改变任何事情和路由到 home#index。我的完整路由文件

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

关于如何在用户登录时让 root 显示位置 ID 的任何想法?

4

3 回答 3

1

您可以通过在终端中运行以下命令来查看与设计相关的所有可用路线。

rake routes
于 2013-01-08T07:21:02.340 回答
1

您可以在经过身份验证的块中使用具有不同名称的根,如下所示:

authenticated :user do
    root to: 'locations#show', :as => authenticated_root
end
于 2013-12-22T23:17:51.957 回答
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  
于 2013-01-08T22:16:15.787 回答