Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the URL without changing the resource name

I'm building a website for a rabbit farmer (let's pretend). This man keeps a close eye on his rabbits, and wants them all categorized. So I built him a RabbitCategoriesController, and added this line to my routes.rb

resources :rabbit_categories 

The URLs are showing up as rabbit_categories, rabbit_categoriew/new, etc.

What if I want the URLs to look like rabits/categories rabits/categories/new instead? This is not a nested resource, I just want to change the way the URLs look.

Of course, if the resources were called "categories", I could do

namespace :rabbits do   resources :categories end 

Is there any way I can write that, but tell it to use the RabbitCategoriesController instead of the Rabbits::CategoriesController?

like image 695
declan Avatar asked Jul 22 '11 07:07

declan


1 Answers

have you tried this, should work

resources :rabbit_categories, :path => "rabbits/categories" 

See Rails Routing from Outside In for more details.

like image 136
rubish Avatar answered Oct 15 '22 06:10

rubish