我试图在我的控制器中接收一些参数,但在允许它们时遇到了问题。这是我的请求负载:
{
contacts: [{
id: null,
address: null,
business: "Company",
cellphone: "",
city: null,
country: null,
email: "[email protected]"
}],
name: "Entity1"
}
在我的控制器中,我定义了:
def update_params
params.permit(
:name,
contacts_attributes: [
:id, :first_name, :last_name, :email, :business, :position, :telephone,
:cellphone, :address, :city, :state, :country
]
)
end
但是当我调用 update_params 方法时,只允许 :name 。不允许接触。我错过了什么吗?
正如我所说,您允许 contacts_attributes
而不是contacts
. update_params
像下面这样更改方法应该可以解决问题。
def update_params
params.permit(
:name,
contacts: [
:id, :first_name, :last_name, :email, :business, :position, :telephone,
:cellphone, :address, :city, :state, :country
]
)
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句