user3461461
user3461461

Reputation: 326

uninitialized constant Controller

I have a problem with routes...

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

When I click on this link:

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

it follow this route localhost:3000/documents/1/user/2/user_unassign and i get an error: uninitialized constant UserController

Routes

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

Upvotes: 1

Views: 11576

Answers (2)

Kirti Thorat
Kirti Thorat

Reputation: 53048

Update your resources :documents routes as below:

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

Upvotes: 0

Monideep
Monideep

Reputation: 2810

change resources :user to resources :users

Update

Change routes.rb file to

#routes.rb
resources :documents do

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

end

and then in your view

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

Note user_unassign_document_user_path will give you a route like localhost:3000/documents/:document_id/users/:id/user_unassign(.:format)

Upvotes: 2

Related Questions