我有两个模型,Car
和Manufacturer
。这些模型非常简单:
class Car < ActiveRecord::Base
attr_accessible :manufacturer_id, :car_name, :descr, ...
belongs_to :manufacturer
...
end
和
class Manufacturer < ActiveRecord::Base
attr_accessible :name, :url
has_many :cars
...
end
views/cars/_form.html.haml
用于输入数据的视图 ( ):
= form_for @car do |f|
.field
= f.label :car_name
= f.text_field :car_name
...
= f.fields_for @manufacturer do |m|
.field
= m.label :name
= m.text_field :name
...
当我发送用于保存输入信息的表单(转到CarsController
)时,我收到此错误:
无法批量分配受保护的属性:制造商
我试图添加
接受嵌套属性:制造商
到Car
模型,但它没有帮助我......
哪里有问题?
编辑: 我如何在控制器中保存数据:
@manufacturer = Manufacturer.new(params[:car][:manufacturer])
@car = @manufacturer.cars.build(params[:car])
EDIT2: 来自日志的数据:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"4vcF5NV8D91DkxpCsqCzfbf05sOYsm7ssxZvPa3+kXo=",
"car"=>{"car_name"=>"...",
"descr"=>"...",
"categroy_ids"=>["2",
"3",
"4"],
"manufacturer"=>{"name"=>"Company",
"url"=>"..."}},
"commit"=>"Save",
"id"=>"..."}
谢谢