Tadashi Mori
Tadashi Mori

Reputation: 118

Changing routes in rails using "resources"

I've got this on routes.rb

 resources :items do
   resources :requisitos
   resources :videos
 end 

and that generates:

                GET    /items/:item_id/requisitos(.:format)          requisitos#index
                POST   /items/:item_id/requisitos(.:format)          requisitos#create
                GET    /items/:item_id/requisitos/new(.:format)      requisitos#new
                GET    /items/:item_id/requisitos/:id/edit(.:format) requisitos#edit
                GET    /items/:item_id/requisitos/:id(.:format)      requisitos#show
                PUT    /items/:item_id/requisitos/:id(.:format)      requisitos#update
                DELETE /items/:item_id/requisitos/:id(.:format)      requisitos#destroy
                GET    /items/:item_id/videos(.:format)              videos#index
                POST   /items/:item_id/videos(.:format)              videos#create
                GET    /items/:item_id/videos/new(.:format)          videos#new
                GET    /items/:item_id/videos/:id/edit(.:format)     videos#edit
                GET    /items/:item_id/videos/:id(.:format)          videos#show
                PUT    /items/:item_id/videos/:id(.:format)          videos#update
                DELETE /items/:item_id/videos/:id(.:format)          videos#destroy
                GET    /items(.:format)                              items#index
                POST   /items(.:format)                              items#create
                GET    /items/new(.:format)                          items#new
                GET    /items/:id/edit(.:format)                     items#edit
                GET    /items/:id(.:format)                          items#show
                PUT    /items/:id(.:format)                          items#update
                DELETE /items/:id(.:format) 

Now, I wanted to change /items to /admin in all routes, how can I do this using recources in this nested resource?

Upvotes: 0

Views: 73

Answers (2)

kayluhb
kayluhb

Reputation: 658

You can set the path on your resources like so

resources :items, path: 'admin' do
    resources :requisitos
end

Upvotes: 1

ryudice
ryudice

Reputation: 37466

I'm not sure if this is what you want but you could do

resources :items, path: "admin"

and that will replace "items" with "admin" in your urls

Upvotes: 0

Related Questions