Forum: Ruby on Rails Help with polymorphic associations... the other way 'round

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
44261b1dd4d1f942a43d19c45e3a22e4?d=identicon&s=25 AdamV (Guest)
on 2009-05-14 01:29
(Received via mailing list)
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.
This topic is locked and can not be replied to.