我改变了我的photo.rb模型具有多态性,并使用到各种其他型号需要保存的图像和除了我无法弄清楚如何正确通过父模型保存新的附件,它工作正常。有任何想法吗?我必须以不同的方式在某种程度上接近这个?由于其还没有得到imageable_type ...我将不得不增加。

我看到了多态的回形针插件,它看起来像一个野兽,并使用另一台?所以我希望有一个更好的解决办法。

我得到:

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.....
有帮助吗?

解决方案

我得到了主意,用accepts_nested_attributes_for因为这是我可以做什么,如果它不是一个多态关联,但另一种模式我在扔属性..瞧,它的工作。

  has_many :photos, :as => :imageable, :dependent => :destroy
  accepts_nested_attributes_for :photos
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top