Forum: Ruby on Rails Mixing Single Table Inheritance and RESTful routes.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Juanma C. (Guest)
on 2007-01-03 20:06
I am trying to implement a restful app, but I have found some problems
with the design, when I have thought in implementig STI.

I will try to explain.
Only as a example, you may suppose this models
Class Person < ActiveRecord::Base
  has_many :widgets

Class Customer < Person

Class Employee < Person

Class Widget < ActiveRecord::Base
  belongs_to :person
Then I would like to define these resources in config/routes.rb
map.resources :customers do |customer|
  customer.resources :widgets
map.resources :employees do |employee|
  employee.resources :widgets

Is this the correct way to abord this problem?
Can I go in the REST style way for this case?

I will appreciate any comment of someone with some experience with these


Juan M. Cervera
Juanma C. (Guest)
on 2007-01-04 12:28
I have tried to find a solution, with no luck.
There is no problem in defining the routes in routes.rb, but it seems
that this will not work because I have only one set of named routes for
the widgets resources.

Does anybody see a better way or an alternative for this problem?

It is important for me because in my real problem I have several classes
that I can implement with STI, they are different resources in my app
and each one needs its resftul controller. But they all have the same
nested resource and I want only one restful controller, for all the
I pretend to be DRY in the design.

Anybody thinks there is a way to implement this?
Please give me some advise.

Thanks in advance.

Juan M. cervera
Juanma C. (Guest)
on 2007-01-08 07:24
I think I have tried very hard and still no luck.

I can have the restful routes working without problems
map.resources :customers do |customer|
  customer.resources :widgets,
                     :name_prefix => 'customer_'
map.resources :employees do |employee|
  employee.resources :widgets
                     :name_prefix => 'employee_'

Now I have named routes like customer_new_widget_path or
employee_widgets_path but I found difficult to be in the DRY way, with
only on controller for widgets, mostly for the associated views.

Is possible that nobody has ever tried something like this?
Or I can't explain the question in a correct way, and nobody understands
Well, I think I'm going to abandon this idea.

Juan M. Cervera
This topic is locked and can not be replied to.