I have an Image class with
belongs_to :attachable, :polymorphic => true
Titles can have Images, and so can People. In the Person class, I have the apposite relationship:
has_many :images, :as => :attachable, :dependent => :destroy accepts_nested_attributes_for :images, :reject_if => lambda { |a| a[:file].blank? && a[:file_uid].blank? && a[:file_url].blank? && a[:name].blank? }, :allow_destroy => true
This all works fine, I've got my forms working perfectly. Now I would like to mark one image as being the "portrait" for this person, and I'm stuck on how best to do this. I have done it in the past in what I recognize was a very hacky manner, just adding an image_id to the parent class and setting that in my controller. I'd rather go with the flow.
How would you add this to the models so that the relationship can be expressed in a normal nested form?
Walter