谷歌搜索了一段时间,没有运气.在传递嵌套属性时,我的Web服务上出现"NoMethodError(未定义方法`with_indifferent_access'"错误.
其他嵌套的工作,它们是一对一的,这是一对多......
class Customer < ActiveRecord::Base
belongs_to :quote
has_one :policy, :dependent => :destroy
has_one :vehicle, :dependent => :destroy
has_many :claims, :dependent => :destroy
has_many :incidents, :dependent => :destroy
accepts_nested_attributes_for :policy
accepts_nested_attributes_for :vehicle
accepts_nested_attributes_for :incidents
end
Run Code Online (Sandbox Code Playgroud)
工作正常:
Processing QuotesController#create to xml (for 127.0.0.1 at 2010-12-12 15:16:33) [POST]
Parameters: {"quote"=>{"customer_attributes"=>{"address1"=>nil, "city"=>"ggh", "dob"=>nil, "address2"=>nil, "title"=>nil, "country"=>nil, "postcode"=>nil, "vehicle_attributes"=>{"mileage"=>nil, "registration"=>nil, "value"=>nil, "parking"=>nil}, "policy_attributes"=>{"breakdown"=>nil, "windscreen"=>"1", "excess"=>nil}, "telephone"=>nil, "surname"=>nil, "forename"=>"wasdddfggh", "email"=>nil}}}
[4;35;1mQuote Create (1.0ms)[0m [0mINSERT INTO "quotes" ("created_at", "updated_at") VALUES('2010-12-12 15:16:33', '2010-12-12 15:16:33')[0m
[4;36;1mCustomer Create (0.0ms)[0m …Run Code Online (Sandbox Code Playgroud)