开发者

change the URL without changing the resource name

开发者 https://www.devze.com 2023-03-22 08:11 出处:网络
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

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 开发者_JAVA技巧write that, but tell it to use the RabbitCategoriesController instead of the Rabbits::CategoriesController?


have you tried this, should work

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

See Rails Routing from Outside In for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消