Ruby on rails 允许Rails中的嵌套参数

Ruby on rails 允许Rails中的嵌套参数,ruby-on-rails,ruby,ruby-on-rails-4,strong-parameters,Ruby On Rails,Ruby,Ruby On Rails 4,Strong Parameters,我想允许一个长的params散列,我试图遵循,但我得到了一些错误,我无法找到什么是错误的 def project_params params.require(:project).permit(:name, :scale, :unit, :colorFormat,

我想允许一个长的params散列,我试图遵循,但我得到了一些错误,我无法找到什么是错误的

def project_params
  params.require(:project).permit(:name,
                                  :scale,
                                  :unit,
                                  :colorFormat,
                                  :artboards => [
                                    {
                                      :layers => [
                                        {
                                          :objectID, :type, :name,
                                          :rect => {
                                            :x, :y, :width, :height
                                          },
                                          :rotation, :radius, :borders => [], :fills => [], :shadows => [], :opacity, :styleName
                                        }
                                      ],
                                      :notes => [
                                        {
                                          :rect => {
                                            :x, :y, :width, :height
                                          },
                                          :note
                                        }
                                      ], :pageName, :pageObjectID, :name, :slug, :objectID, :width, :height, :imagePath
                                    }
                                  ],
                                  :slices => [
                                    :name, :objectID,
                                    :rect => {
                                      :x, :y, :width, :height
                                    },
                                    :exportable => [
                                      {
                                        :name, :density, :format, :path
                                      }
                                    ]
                                  ],
                                  :colors => [
                                  ]
                                 )
end
以下是我得到的错误:

projects_controller.rb:60: syntax error, unexpected ',', expecting =>
...=> [ {:layers => [ { :objectID, :type, :name, :rect => {:x, ...
...                               ^
projects_controller.rb:60: syntax error, unexpected ',', expecting =>
...ID, :type, :name, :rect => {:x, :y, :width, :height}, :rotat...
...                               ^
projects_controller.rb:60: syntax error, unexpected ',', expecting =>
... } ], :notes => [{:rect => {:x, :y, :width, :height}, :note}...
...                               ^
projects_controller.rb:60: syntax error, unexpected ',', expecting =>
...:name, :objectID, :rect => {:x, :y, :width, :height}, :expor...
...                               ^
projects_controller.rb:60: syntax error, unexpected ',', expecting =>
...eight}, :exportable => [{:name, :density, :format, :path}], ...
...                               ^):
我不知道为什么它期望
=>
而不是
,而我只需要一个标量值,而不是数组或散列。我错过了什么

编辑

现在我修复了大多数参数:

  params.require(:project).permit(:slug,
                                  :scale,
                                  :unit,
                                  :color_format,
                                  artboards: [
                                    :page_name, :page_object_id, :name, :slug, :object_id, :width, :height, :image_path,
                                    layers: [
                                      :object_id, :type, :name, :rotation, :radius, :opacity, :style_name, :font_size, :font_face, :text_align, :letter_spacing, :line_height, :content, rect: [], css: [], borders: [], fills: [], shadows: [], color: []
                                    ],
                                    notes: [
                                      :note,
                                      rect: [
                                        :x, :y, :width, :height
                                      ]
                                    ]
                                  ],
                                  slices: [
                                    :name, :object_id,
                                    rect: [
                                      :x, :y, :width, :height
                                    ],
                                    exportable: []
                                  ],
                                  colors: []
                                 )
我得到:

Unpermitted parameter: rect
Unpermitted parameter: rect
Unpermitted parameters: rect, fills
Unpermitted parameters: rect, color
Unpermitted parameters: rect, borders
Unpermitted parameters: rect, color
Unpermitted parameters: exportable, rect

下面是一个JSON示例:

它似乎在说,因为您将这些符号包装在
{}
中,所以它需要一个散列,这意味着您需要一个键和值,如
:objectID=>一些\u值

在这方面,

{ :objectID, :type, :name, :rect => {:x, ...
它期待着类似这样的事情

{ :objectID => val1, :type => val2, :name => val3, :rect => {:x, ...
这直接取自嵌套参数的强参数文档

params.permit(:name, {:emails => []}, :friends => [ :name, { :family => [ :name ], :hobbies => [] }])

请注意,
{}
中的所有内容都始终有一个键值对。例如
{:emails=>[]}
{:family=>[:name],:cabiods=>[]}
似乎是说,因为您将这些符号包装在
{}
中,所以它需要一个散列,这意味着您需要一个键和值,比如
:objectID=>一些u值

在这方面,

{ :objectID, :type, :name, :rect => {:x, ...
它期待着类似这样的事情

{ :objectID => val1, :type => val2, :name => val3, :rect => {:x, ...
这直接取自嵌套参数的强参数文档

params.permit(:name, {:emails => []}, :friends => [ :name, { :family => [ :name ], :hobbies => [] }])

请注意,
{}
中的所有内容都始终有一个键值对。例如
{:emails=>[]}
{:family=>[:name],:cabiods=>[]}

谢谢@davidhu2000,这很有效,但是我在访问嵌套哈希时遇到了这个错误:谢谢@davidhu2000,这很有效,但是我在访问嵌套哈希时遇到了这个错误: