james
unread,Jul 9, 2009, 5:55:03 PM7/9/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message as abuse
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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