views:

404

answers:

1

I changed my photo.rb model to be polymorphic and be usable to all sorts of other models needing to save images and it works fine except I can't figure out how to save new attachments properly through the parent model. Any ideas? Do I have to approach this differently somehow? As, its also not getting the imageable_type...which i'll have to add.

I saw the polymorphic paperclip plugin which looks like a beast and uses yet another table? So I'm hoping for a better work around.

I'm getting:

ActiveRecord::AssociationTypeMismatch (Photo(#2189565500) expected, got Array(#2148226700))

Parameters: {"commit"=>"Create", "action"=>"update", "_method"=>"put", "authenticity_token"=>"kp7NeMs7moGwu0AZMXVowUpphp9vzitdZZ6t8YO7RKQ=", "id"=>"2586", "muffin"=>{"photos"=>{"data"=>#<File:/var/folders/4d/4dqp9CQQEbmM1akqbtLxzk+++TI/-Tmp-/RackMultipart20100218-11622-onqem2-0>}}, "controller"=>"muffins"}

muffin.rb

has_many :photos, :as => :imageable, :dependent => :destroy

photo.rb

belongs_to :imageable, :polymorphic => true
has_attached_file :data,
    :storage => 's3',
    :s3_credentials.....
+1  A: 

I got the idea to use accepts_nested_attributes_for since that's what I might do if it wasn't a polymorphic association but another model i was throwing attributes at.. and voila, it worked.

  has_many :photos, :as => :imageable, :dependent => :destroy
  accepts_nested_attributes_for :photos
holden