Rails 嵌套属性文件上传错误 - 预期数组(得到 Rack::Utils::KeySpaceConstrainedParams)

Rails nested attributes file uploading error - expected Array (got Rack::Utils::KeySpaceConstrainedParams)

我正在尝试使用嵌套属性上传图片,但出现此错误:

Rack::Utils::ParameterTypeError - expected Array (got Rack::Utils::KeySpaceConstrainedParams) for param `project_images_attributes':

每当我编辑我的项目以添加新图像时。我想如果我添加 child_index: ProjectImage.new.object_id,它会起作用

<%= f.simple_fields_for :photos, ProjectImage.new, child_index: ProjectImage.new.object_id do |ff| %>
  <%= ff.label :photo, "Upload Photo" %>
  <%= ff.file_field :photo, multiple: true, name: "project[project_images_attributes][][photo]" %>
<% end %>

编辑:

ProjectImage 模型

class ProjectImage < ActiveRecord::Base
  belongs_to :project

  paperclip_opts = {
    :styles => { :large => "800x800>", :medium => "x430>", :frontpage_thumb => "130x95#", :thumb => "150x150#" }, 
    :convert_options => { :all => "-quality 75 -strip" }
  }

  has_attached_file :photo, paperclip_opts
  validates_attachment_content_type :photo, content_type: /\Aimage\/.*\Z/

end

项目模型

class Project < ActiveRecord::Base
  has_many :project_images, dependent: :destroy

  accepts_nested_attributes_for :project_images, allow_destroy: true
end

你需要改变这个

<%= f.simple_fields_for :photos, ProjectImage.new, child_index: ProjectImage.new.object_id do |ff| %>

<%= f.simple_fields_for :project_images, ProjectImage.new, child_index: ProjectImage.new.object_id do |ff| %>