Subclassing and STI

0 views
Skip to first unread message

james

unread,
Jul 9, 2009, 5:55:03 PM7/9/09
to resource_controller
Having some difficulty getting single table inheritance with
subclassed r_c controllers.

What I'd really like to be able to do to (and thus far my testing has
shown this doesn't work) is something like this:

map.resources :lists
map.resources :foo_lists, :controller => 'lists'
map.resources :bar_lists, :controller => 'lists'

class ListsController < ResourceController::Base
end

(no foo or bar list controller)

class List < ActiveRecord::Base
end

class FooList < List
end

class BarList < List
end

And then have r_c automagically return the appropriate model (inferred
from the route) for the object/model/collection helpers.

As I said, that would be nice... But so far the helpers are only
returning the List model.

I'm also totally willing to accept:

map.resources :lists
map.resources :foo_lists
map.resources :bar_lists

class ListsController < ApplicationController
resource_controller
index.wants.html { render 'lists/index' }
new_action.wants.html { render 'lists/new' }
...etc...
end

class FooListsController < ListsController
end

class BarListsController < ListsController
end

class List < ActiveRecord::Base
end

class FooList < List
end

class BarList < List
end

But this too seems to only return the List model for each of the
helpers.

After some messing around I was finally able to get the model I was
looking for with this:

class FooListsController < ListsController
private
def model_name
'foo_lists'
end
end

Which is better than nothing, I suppose. I was just really looking
forward to a super slick solution. I mean, don't get me wrong, there's
a lot of free functionality with what's above. But the model_name
thing seems hackish somehow, yeah?

Anyway, anyone have any ideas towards the super simple approach? Or,
if I have to stick with the model_name thing, are there any caveats /
pitfalls I need to watch out for?

Thanks,
james
Reply all
Reply to author
Forward
0 new messages