Strong parameters for nested attributes returns “unpermitted parameters” when empty array

前端 未结 1 1305
臣服心动
臣服心动 2020-12-19 03:12

Assuming a User model using Rails4 with strong_parameters.

class User < ActiveRecord::Base
  has_secure_password

 accepts_nested_attributes_for :identit         


        
相关标签:
1条回答
  • 2020-12-19 03:51

    You have to specify the identity's attributes you want to updated, including the :id of the identity entity.

    you will have something like that :

    def user_params 
      params.require(:user).permit(:email, identity_attributes: [:id, :last_name, :first_name]) 
    end
    

    if you don't specify the :id, Rails will try to create an entity instead of updating it. I spend all the week-end struggling on a simple one-to-many relationship using accepts_nested_attributes_for because I didn't specified the id in the permitted attributes.

    0 讨论(0)
提交回复
热议问题