Rails: Unpermitted parameter in Rails 5

后端 未结 2 1493
感动是毒
感动是毒 2020-12-14 07:46

First of all I want simply get an object inside the current object that I\'m sending to my backend.

I have this simple JSON (generated from a f

2条回答
  •  臣服心动
    2020-12-14 08:29

    It's not the inflection of the word "criteria" that's giving you problems (although you can add a custom inflector to get the singular and plural versions you prefer if you really want).

    The issue is that you have to explicitly permit the fields of nested objects.

    Change your current params:

    params.require(:project).permit(:name,  project_criteria: [] )
    

    To this (for a single nested object):

    params.require(:project).permit(:name,  project_criteria: [:name, :type, :benefit] )
    

    Your case is somewhat compounded by the fact that you're dealing with multiple nested objects, so you'll have to pass a hash instead:

    params.require(:project).permit(:name,  { project_criteria: [:name, :type, :benefit]} )
    

提交回复
热议问题