Rails 5.1 API - how to permit params for nested JSON object's attributes
I think you forget that params.require(:template).permit( ... is a method that is returning a value and when you call params to modify it later you are only modifying params that have not been permitted yet. what you want to do is swap the order of when you are performing the parameter manipulation.
def template_params
params[:template][:template_items_attributes] = params[:template_items_attributes]
params.require(:template).permit(:id, :account_id, :name, :title, :info, template_items_attributes: [:id, :is_completed, :content, :item_type])
end
UPDATE: wrap_parameters was the culprit as it was not including nested parameters in the wrapped params. this fixes the issue
UPDATE: this answer implements a different solution Rails 4 Not Updating Nested Attributes Via JSON
This is a long open request in github!! crazy https://github.com/rails/rails/pull/19254
UPDATE: this was finally merged in AR 6 https://github.com/rails/rails/commit/62b7ad46c0f3ff24980956daadba46ccb2568445