Chris Muench
Chris Muench

Reputation: 18318

Nested Resource Routing

resources :patients do
 collection do
   get 'new_import'
   post 'import'
 end

How can I have the following urls?

/patients/import (GET) -->ACTION: new_import

/patients/import (POST) --> ACTION: import

Right NOW THE URLS ARE:

/patients/new_import (GET) -->ACTION: new_import

/patients/import (POST) --> ACTION: import

I must be able to do this WITHOUT doing:

 match 'patients/import' => 'patients#new_import', :via => :get
 match 'patients/import' => 'patients#import', :via => :post

Upvotes: 1

Views: 99

Answers (2)

codebrane
codebrane

Reputation: 4620

resources :patients do
  collection do
    get  'import' => :new_import
    post 'import' => :import
  end
end

Upvotes: 2

Adrian Serafin
Adrian Serafin

Reputation: 7705

Like you've written on top:

resources :patients do
 collection do
   get 'new_import'
   post 'import'
 end
end

Do you have any errors while trying to access this urls?

Upvotes: 1

Related Questions