我無法讓我的InventoryItem接受奇怪的嵌套屬性。Rails中嵌套窗體的未知屬性
在我的腳本/控制檯,我做了以下內容:
>> InventoryItem.create!(:name => 'what', :image_attributes => [ {:image => File.open("/home/davidc/Desktop/letterbx.jpg", "r") }])
ActiveRecord::UnknownAttributeError: unknown attribute: image_attributes
我不知道爲什麼,我發現了未知屬性錯誤時,在我的模型,我已經做了accept_nested_attributes。
我正在使用Rails v2.3.5。
庫存項目型號
class InventoryItem < ActiveRecord::Base
uuid_it
belongs_to :user
has_many :orders
has_many :images, :validate => true
accepts_nested_attributes_for :images
end
圖片
class Image < ActiveRecord::Base
belongs_to :inventory_item
has_attached_file :image, :style => { :medium => "300x300>", :thumb => "100x100>" }
end