Help with polymorphic associations... the other way 'round


#1

Good afternoon,

I have a situation were I have Container model which has_many Item
models (as a list). Now each Item can be either a TextItem (a chunk of
HTML) or a FeedItem (some RSS Feed) – in the future I’ll add other
Item types.

My first thought is to have the following:

class Container < ActiveRecord::Base
has_many :items, :order => “position”
end

class Item < ActiveRecord::Base
belongs_to :container
acts_as_list :scope => :container
belongs_to :content, :polymorphic => true
end

class TextItem < ActiveRecord::Base
has_one :item, :as => :content
end
class FeedItem < ActiveRecord::Base
has_one :item, :as => :content
end

My problem comes in at the view. None of these models are particularly
complicated so I’d like to show and edit them inline with the
container views. I’m really at a loss as to where to start, what I
need to do to keep stuff connected, &c.

This seems like its a lot more complex than than standard nested form
example so I’m hoping someone has an idea of where to start or even a
link to some tutorial/article that will provide some illumination.