I have a Model Property which has subclasses using STI,
and which I would like all to use the same controller with only different view partials depending on the subclass.
Property
Restaurant < Property
Landmark < Property
It works find except I’m not sure how to discern the subclass inside the controller to render the correct view. Ie. /restaurants works and goes to the properties controller but I can’t tell that they want the Restaurant subclass?
map.resources :restaurant, :controller => :properties
map.resources :properties
A simple way to fi the problem would be to create a Sub-Controller:
In the routes you would map restaurants to the restaurants controller.
Update: Alternatively you could try something like this in your
routes.rb:Then you can use a before filter to check params[:what] and change behaviour accordingly.
Example: