2
我已經嘗試使用白名單標識,但它無濟於事,無論如何都會創建重複項。Rails 4在更新嵌套屬性時創建重複項
型號:
accepts_nested_attributes_for :address, :social, :contact, :talent_parameter
我傳遞的屬性:
model_attributes = {
talent_parameter_attributes: {
},
contact_attributes: {
agency_link: base_url + href
},
social_attributes: {
},
address_attributes: {
}
}
update_model(model, model_attributes)
我設置的權限:
def self.update_model(model, attrs)
params = ActionController::Parameters.new(model: attrs)
model_params = params.require(:model)
model_params = model_params.permit(
:company,
:age,
:avatar,
:gender,
:contact_id,
talent_features: [],
talent_parameter_attributes: [:id, :weight_lbs, :dress, :shoe, :chest, :waist, :hips, :height_ft],
contact_attributes: [:id, :agency_link],
social_attributes: [:id]
)
model.update(model_params)
end
我不明白。每次創建talent_parameter
,contact
,social
和address
的另一個副本。它有什麼問題?