开发者

Can I map resources to a different controller?

开发者 https://www.devze.com 2022-12-11 11:06 出处:网络
I have my resources already defined, but a client wants to change the names of the URLs to match开发者_运维问答 their brand (e.g. something like \"catalog\" when the resource is currently \"products\"

I have my resources already defined, but a client wants to change the names of the URLs to match开发者_运维问答 their brand (e.g. something like "catalog" when the resource is currently "products"). Can I specify a different controller name with a resource so I can get all the built-in resources functionality without having to actually rename the controller and model names?


For the record: map.resources :products, :controller => "catalog" is how you do this.


The rails guide specifies how to use specific controllers for certain routes.

You can do something like this:

Rails.application.routes.draw do
  resources :products, controller: "catalog" 
  # but rails conventions suggests you should pluralise your controller name
  # so use "catalogs" (plural) instead of the singular "catalog"
end


Okay it looks like it's as simple as adding the controller name, and it seems to be working. Nevermind!

0

精彩评论

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