I have a project
that has buildings
that have address
. When I create a building, no problems arise. When I edit the building, I get Unpermitted parameter: :id
In my building.rb:
permit_params :name, :construction_year, :floors, :building_type, :energy_label, :owner_id, :manager_id, :project_ids,
address_attributes: [:street, :number, :postal_code, :city]
Parameters: {"utf8"=>"✓", "authenticity_token"=>"jNSKHkHXRr6W8+1vrpg6ZO8QN34zsByq8Hl/dkz0KFR2o4eU61qaHr3mVUQFfMoxKvjxX096N8a5kOPFw4QP5Q==", "building"=>{"project_ids"=>"1b4a46df-62bc-44ec-8915-e0d3b5e8b398", "name"=>"a1", "construction_year"=>"2010", "floors"=>"5", "building_type"=>"single_tenant", "energy_label"=>"A++", "owner_id"=>"98f74ca0-986f-4733-91e6-185a7c7920f5", "manager_id"=>"98f74ca0-986f-4733-91e6-185a7c7920f5", "address_attributes"=>{"street"=>"lane", "number"=>"1", "postal_code"=>"0000aa", "city"=>"somewhere", "id"=>"049e44df-6d0d-4c86-9ea8-34aba5b8d5f8"}}, "commit"=>"Update Building", "id"=>"db66a4fd-768b-4315-a4e9-3e7aa04d9cdf"}
The id that is unpermitted is: "id"=>"db66a4fd-768b-4315-a4e9-3e7aa04d9cdf"
I tried adding it as follows (also in different ways like building_id), but it doesn't remove the message.
permit_params :id, :name, :construction_year, :floors, :building_type, :energy_label, :owner_id, :manager_id, :project_ids,
address_attributes: [:street, :number, :postal_code, :city]
Please advise.
It's not the building :id
, it's the address_attributes
that should have the :id
added.
So in building.rb
:
permit_params :name, :construction_year, :floors, :building_type, :energy_label, :owner_id, :manager_id, :project_ids,
address_attributes: [:id, :street, :number, :postal_code, :city]
add :id
to your nested attributes
permit_params :id, :name, :construction_year, :floors, :building_type, :energy_label, :owner_id, :manager_id, :project_ids,
address_attributes: [:id, :street, :number, :postal_code, :city]
add :id to address_attributes
permit_params :name, :construction_year, :floors, :building_type, :energy_label, :owner_id, :manager_id, :project_ids,
address_attributes: [:id, :street, :number, :postal_code, :city]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.