Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I map resources to a different controller?

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?

like image 619
Wayne Molina Avatar asked Nov 12 '09 15:11

Wayne Molina


2 Answers

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

like image 54
Ryan Bigg Avatar answered Sep 28 '22 15:09

Ryan Bigg


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
like image 25
BenKoshy Avatar answered Sep 28 '22 16:09

BenKoshy