how to permit an array with strong parameters

前端 未结 5 487
说谎
说谎 2020-11-22 13:50

I have a functioning Rails 3 app that uses has_many :through associations which is not, as I remake it as a Rails 4 app, letting me save ids from the associated model in the

5条回答
  •  自闭症患者
    2020-11-22 14:19

    If you want to permit an array of hashes(or an array of objects from the perspective of JSON)

    params.permit(:foo, array: [:key1, :key2])
    

    2 points to notice here:

    1. array should be the last argument of the permit method.
    2. you should specify keys of the hash in the array, otherwise you will get an error Unpermitted parameter: array, which is very difficult to debug in this case.

提交回复
热议问题