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