1
我想使用字符串参数来允许传递模型的嵌套属性,无论出于何种原因permit
方法忽略任何嵌套的属性。请看下图:嵌套属性的强参数被忽略
型号:
class User < ActiveRecord::Base
accepts_nested_attributes_for :phone_number, :address, update_only: true
accepts_nested_attributes_for :profession, update_only: true
end
控制器:
class Api::V1::Users::UsersController < Api::BaseController
def update
permitted = permitted_user_params
end
def permitted_user_params
params.require(:profile).permit(
:first_name,
:last_name,
:password,
:password_confirmation,
phone_number_attributes: [:phone_number],
address_attributes: [:street, :city, :province, :country, :postal_code],
profession_attributes: [:company, :title, :designation]
)
end
end
如果我通过正确格式化数据permitted_user_params将不返回其他任何值比first_name, last_name, password and password_confirmation
。
谁能告诉我我做错了什么?
谢谢
我想你忘记了嵌套模型的ID:'phone_number_attributes:[:身份证,电话号码:PHONE_NUMBER], address_attributes:[:ID,:街道:城市:省:国家:POSTAL_CODE], profession_attributes: :id,:company,:title,:指定]' – Thanh 2014-08-28 08:57:35
为每个包含':id'似乎没有任何作用。 – adampetrie 2014-08-28 13:23:36
你有没有想过这个呢?我看到同样的事情。 – MFrazier 2015-02-03 00:50:36