2014-03-25 162 views
1

我有路線問題...未初始化的常數控制器

的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' %> 

它遵循這條路線本地主機:3000/documents/1/user/2/user_unassign,我得到一個錯誤:未初始化的常量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 
+0

我不認爲你的定義路徑是正確的。 – Severin

+0

document_user_user_unassign DELETE /documents/:document_id/user/:user_id/user_unassign(.:format)user#user_unassign – user3461461

+0

用戶控制器的名稱是什麼? –

回答

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 
+0

它的工作,謝謝:) – user3461461

+0

很高興幫助。請接受答案,如果它解決了你的問題:) –

2

變化resources :userresources :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)

+0

我試過了,但是同樣的問題 – user3461461

+1

可以分享嗎運行耙路線的輸出? – Monideep

+0

我不能粘貼所有這些,我編輯頂部。涉及的路線是document_user_user_unassign DELETE /documents/:document_id/user/:user_id/user_unassign(.:format)用戶#user_unassign – user3461461