has_many through和accepts_nested_attributes_for的强参数

时间:2013-07-30 11:04:08

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 strong-parameters

这是我的模特

class UnitPlate < ActiveRecord::Base
   has_many :unit_plate_components, :dependent => :destroy
   accepts_nested_attributes_for :unit_plate_components, :allow_destroy => true
   has_many :components, :through => :unit_plate_components
end

这就是我写的allowed_pa​​rams

的方式
def unit_plate_params
  params.require(:unit_plate).permit(:name,:name_type,:type,:unit_plate_components_attributes => [:id, '_destroy',:component_id,:name,:type,:parent_id,:lft,:rgt,:depth])
end

It is complaining about this on save which is not saving my record

Unpermitted parameters: component_id, _destroy
Unpermitted parameters: name_type

This is the raw parameters

  Parameters: {"utf8"=>"✓", "authenticity_token"=>"CfGubZxXPW/7XEHEhnFTjKVKByNxGb5r3KJqoqoXHms=", "unit_plate"=>{"name"=>"okay", "name_type"=>"cool", "parent_id"=>"", "unit_plate_components_attributes"=>{"1375181809419"=>{"component_id"=>"181", "_destroy"=>"false"}}}, "commit"=>"Create Unit plate"}

关于出了什么问题的任何线索?

先谢谢。

0 个答案:

没有答案