Nick Ginanto
Nick Ginanto

Reputation: 32140

Alternate model name in routes

I have a house model giving route like

/house/:id

In some cases, I would (or the user, in a very dynamic way) that a house is cabin, cottage, building, farm, etc, out of a predefined list. The selection is made depending on what the user inputs, without letting the user choose, so it depends on logic which can change

Is there a way to create alternate route that if the logic decides that the house is a cabin that it will have routes of

/cabin/:id

that will route it to the houses controller and the appropriate action? (same for other alternate names)

I can't use STI since the instance is a house, and can change its 'type' dynamically

Upvotes: 0

Views: 31

Answers (1)

usha
usha

Reputation: 29349

You can try something like this

in your routes

resources :house
resources :cabin, :controller => "houses"
resources :cottage, :controller => "houses"
resources :building, :controller => "houses"

run rake routes and make sure if it works as expected

Upvotes: 2

Related Questions