我一直得到一个ActiveRecord :: UnknownAttributeError:
未知属性:imageable_id
代码:
多态图像模型:
class Image < ActiveRecord::Base
mount_uploader :asset, ImageUploader
belongs_to :imageable, :polymorphic => true
end
正在尝试针对2种不同图像类型进行多态关联的模型:
has_one :image, :as => :imageable, :dependent => :destroy
accepts_nested_attributes_for :image
has_one :thumbnail, :as => :imageable, :dependent => :destroy
accepts_nested_attributes_for :thumbnail
尝试构建图像的控制器操作(第一个“build_image”实际触发,错误引用“build_thumbnail”:
def new
@item = @item_class.new #item is instantiated elsewhere
@item.build_image #this works
@item.build_thumbnail #this throws my error "unknown attribute: imageable_id"
end
谢谢!
修改编辑
答案 0 :(得分:1)
您只需要添加:class_name =&gt; has_one:thumbnail关系的图像选项。 (thx检查我@Tilo)