2
我不斷收到一個ActiveRecord :: UnknownAttributeError:Rails 3 - 將每個模型的多態圖像模型附加爲不同的圖像類型,我做錯了什麼?
未知屬性: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
的感謝!
編輯固定
我*認爲*您需要添加:class_name =>圖像選項has_one:thumbnail關係,但我沒有發佈正式答案,因爲我沒有時間測試:) –
@Chris:我同意!你應該把它作爲答案 – Tilo