未初始化的常量控制器

时间:2014-03-25 20:05:04

标签: ruby-on-rails ruby ruby-on-rails-4

我的路线有问题......

routes.rb

resources :documents do

  resources :user do
     delete 'user_unassign'
  end

  resources :attachments do    
    collection do
      get :index_parent_attachments
    end
  end

end

resources :document_types do
   resources :documents
end



devise_scope :user do
     #    root :to => "devise/sessions#new" #, :as => :root
 end

       devise_for :users 

 namespace :admin do
   resources :users, :document_types
 end

当我点击此链接时:

<%= link_to 'unfollow', document_user_user_unassign_path(document, user.id), :method => 'delete' %>

它遵循这条路由localhost:3000 / documents / 1 / user / 2 / user_unassign我得到一个错误:uninitialized constant UserController

路线

Prefix Verb   URI Pattern                                                            Controller#Action
                                         root GET    /                                                                      profiles#dashboard
                                    user_root GET    /profiles/dashboard(.:format)                                          profiles#dashboard
                  document_user_user_unassign DELETE /documents/:document_id/user/:user_id/user_unassign(.:format)          user#user_unassign
                          document_user_index GET    /documents/:document_id/user(.:format)                                 user#index
                                              POST   /documents/:document_id/user(.:format)                                 user#create
                            new_document_user GET    /documents/:document_id/user/new(.:format)                             user#new
                           edit_document_user GET    /documents/:document_id/user/:id/edit(.:format)                        user#edit
                                document_user GET    /documents/:document_id/user/:id(.:format)                             user#show
                                              PATCH  /documents/:document_id/user/:id(.:format)                             user#update
                                              PUT    /documents/:document_id/user/:id(.:format)                             user#update
                                              DELETE /documents/:document_id/user/:id(.:format)                             user#destroy
index_parent_attachments_document_attachments GET    /documents/:document_id/attachments/index_parent_attachments(.:format) attachments#index_parent_attachments
                         document_attachments GET    /documents/:document_id

2 个答案:

答案 0 :(得分:2)

resources :user 更改为 resources :users

更新

将routes.rb文件更改为

#routes.rb
resources :documents do

  resources :users do
     member do
       delete 'user_unassign'
     end
  end

end

然后在你的视图中

<%= link_to 'unfollow', user_unassign_document_user_path, :method => 'delete' %>

注意 user_unassign_document_user_path 会为您提供类似localhost:3000/documents/:document_id/users/:id/user_unassign(.:format)

的路线

答案 1 :(得分:0)

更新您的resources :documents路线,如下所示:

resources :documents do

  namespace :admin do       ## Added namespace
    resources :users do     ## updated resources as users(plural)
      delete 'user_unassign'
    end
  end                       ## end of :admin namespace 

  resources :attachments do    
    collection do
      get :index_parent_attachments
    end
  end

end