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

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”

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

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs