Reputation: 1415
I'm trying to recieve some params within my controller, but I'm having issues when permitting them. This is my request payload:
{
contacts: [{
id: null,
address: null,
business: "Company",
cellphone: "",
city: null,
country: null,
email: "[email protected]"
}],
name: "Entity1"
}
Inside my controller, I defined:
def update_params
params.permit(
:name,
contacts_attributes: [
:id, :first_name, :last_name, :email, :business, :position, :telephone,
:cellphone, :address, :city, :state, :country
]
)
end
But when I call the update_params method, only :name is permitted. Contacts is unpermitted. Am I missing something?
Upvotes: 1
Views: 502
Reputation: 169
First check in your model you have written accept_nested_attributes_for :contacts
if yes then your code must work.
Upvotes: -1
Reputation: 33552
As I said, you are permitting contacts_attributes
instead of contacts
. Changing the update_params
method like below should fix the problem.
def update_params
params.permit(
:name,
contacts: [
:id, :first_name, :last_name, :email, :business, :position, :telephone,
:cellphone, :address, :city, :state, :country
]
)
end
Upvotes: 4