views:

17

answers:

1

Is there an elegant way of having multiple names for a single resource. We would like to give the user a choice via a setting of what they would like to call their "things". I.e. products, items, services whatever.

So far I can only think of using multiple routes to a single controller:

resources :products
resources :items, :controller => :products
resources :services, :controller => :products

The only thing I can see is the views will become quite complex having to ask which URL to generate based on the users setting.

Any thoughts or ideas would be appreciated!

A: 

Not sure exactly what you you're trying to do but Rails can do all of the heavy lifting for URL generation through the url_for helper. See here

bjg
if I do url_for(@product) that will create products/1 for example right? The user may haven choosen to call products services, therefore I'd like url_for(@product) to generate services/1 In the DB its the same resource, just a different name for it.
tsdbrown
OK, I see. Then I suggest you add an alias attribute (a string) to the base models that can have different names populate this with the user selected name. When it comes to getting the URL just fetch the alias and you should get what you want
bjg