0

所以我有一个 User 类和每个 user 的设计设置has_many :items。我正在尝试将登录用户的根目录更改为他们项目的索引页面。

这是我的 routes.rb 文件:

RequestApp::Application.routes.draw do
  devise_for :users

  resources :users do
    resources :items
  end

  authenticated :user do
    root :to =>  'users/:user_id/items#index'
  end

  devise_scope :user do
    root :to => 'devise/sessions#new'
  end

然后运行 ​​rake routes 让我:

        new_user_session GET    /users/sign_in(.:format)                 devise/sessions#new
            user_session POST   /users/sign_in(.:format)                 devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                devise/sessions#destroy
           user_password POST   /users/password(.:format)                devise/passwords#create
       new_user_password GET    /users/password/new(.:format)            devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)           devise/passwords#edit
                         PUT    /users/password(.:format)                devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                  registrations#cancel
       user_registration POST   /users(.:format)                         registrations#create
   new_user_registration GET    /users/sign_up(.:format)                 registrations#new
  edit_user_registration GET    /users/edit(.:format)                    registrations#edit
                         PUT    /users(.:format)                         registrations#update
                         DELETE /users(.:format)                         registrations#destroy
              user_items GET    /users/:user_id/items(.:format)          items#index
                         POST   /users/:user_id/items(.:format)          items#create
           new_user_item GET    /users/:user_id/items/new(.:format)      items#new
          edit_user_item GET    /users/:user_id/items/:id/edit(.:format) items#edit
               user_item GET    /users/:user_id/items/:id(.:format)      items#show
                         PUT    /users/:user_id/items/:id(.:format)      items#update
                         DELETE /users/:user_id/items/:id(.:format)      items#destroy
                   users GET    /users(.:format)                         users#index
                         POST   /users(.:format)                         users#create
                new_user GET    /users/new(.:format)                     users#new
               edit_user GET    /users/:id/edit(.:format)                users#edit
                    user GET    /users/:id(.:format)                     users#show
                         PUT    /users/:id(.:format)                     users#update
                         DELETE /users/:id(.:format)                     users#destroy
                    root        /                                        users/:user_id/items#index
                    root        /                                        devise/sessions#new

登录并去给localhost:3000我一个路由错误:uninitialized constant Users

我试过把它改成

  authenticated :user do
    root :to =>  'items#index'
  end

这让我犯了错误No route matches {:action=>"new", :controller=>"items"}

我似乎无法在任何地方找到解决方案。有谁知道我做错了什么?谢谢!

4

1 回答 1

0

因此,事实证明正确的路线是后者:

authenticated :user do
  root :to =>  'items#index'
end

我得到的错误实际上来自我的观点。我不得不从视图中删除 new_user_item_path link_to。在此之后,我将弄清楚如何链接到新项目。

于 2013-05-29T19:04:59.143 回答