我正在尝试使用一些嵌套属性创建记录,并且嵌套属性位于多态模型中;像这样的东西:
class Office < ActiveRecord::Base
attr_accessible :name, :description, :address_attributes
has_one :address, as: :location_data_source
accepts_nested_attributes_for :address
end
class Shop < ActiveRecord::Base
attr_accessible :name, :description, :address_attributes
has_one :address, as: :location_data_source
accepts_nested_attributes_for :address
end
class Address < ActiveRecord::Base
attr_accessible :street, :city
belongs_to :location_data_source, polymorphic: true
end
我想创建这样的记录:
o = Office.create(:name = 'The Big Office', description = 'a really big office' :address_attributes => [:street => 'main street', :city => 'No Name City'])
但我收到一个“with_indifferent_access”错误:
NoMethodError:未定义的方法“with_indifferent_access”用于...
我想我很挣扎,因为我真的不明白错误的含义。有任何想法吗?