Ruby on rails Rails中嵌套表单上的未知属性

Ruby on rails Rails中嵌套表单上的未知属性,ruby-on-rails,activerecord,nested-forms,Ruby On Rails,Activerecord,Nested Forms,我很难让我的InventoryItem接受嵌套属性,这很奇怪 在我的脚本/控制台中,我执行了以下操作: >> InventoryItem.create!(:name => 'what', :image_attributes => [ {:image => File.open("/home/davidc/Desktop/letterbx.jpg", "r") }]) ActiveRecord::UnknownAttributeError: unknown attrib

我很难让我的InventoryItem接受嵌套属性,这很奇怪

在我的脚本/控制台中,我执行了以下操作:

>> InventoryItem.create!(:name => 'what', :image_attributes => [ {:image => File.open("/home/davidc/Desktop/letterbx.jpg", "r") }])
ActiveRecord::UnknownAttributeError: unknown attribute: image_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 InventoryItemtrue
接受图像的\u嵌套\u属性\u
结束
形象

类映像{:medium=>“300x300>”,:thumb=>“100x100>”}
结束

:图像属性应该是散列

InventoryItem.create!(
   :name => 'what',
   :image_attributes => { ... }
)

你有
有很多:图像
因此,它应该是
:images\u attributes
,而不是
:images\u attributes

InventoryItem.create!(:name => 'what', :images_attributes => [ {:image => File.open("/home/davidc/Desktop/letterbx.jpg", "r") }])
当您有多个
关系时,使用哈希数组是正确的

InventoryItem.create!(:name => 'what', :images_attributes => [ {:image => File.open("/home/davidc/Desktop/letterbx.jpg", "r") }])