我无法让我的 InventoryItem 接受奇怪的嵌套属性。
在我的脚本/控制台中,我执行了以下操作:
>> 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