0

我正在尝试通过 1 个表单上传带有回形针的多张图片,但我收到了 Unpermitted parameters 错误。

这是我的代码:

模型:

class Recentjacket < ActiveRecord::Base

  has_attached_file :jacketimage, :styles => { :medium => "300x300>", :thumb => "100x100>"}, :default_url => "/images/:style/missing.png"

end

控制器:

def recent
  @recentjacket = Recentjacket.all
end

def update
  params['recentjacket'].keys.each do |id|
  @jacket = Recentjacket.find(id)

  @jacket.update_attributes(recentjacket_params)
  end

  redirect_to '/recent'
end

private
  def recentjacket_params
    params.require(:recentjacket).permit(:jacketimage)
  end

html.slim

= form_for recent_path, html: { multipart: true } do |k| 
  - @recentjacket.each do |j|
    = fields_for "recentjacket[]", j do |jacketfields|
      = jacketfields.file_field :jacketimage

    = k.submit "Update"

因此,数据库中基本上有 12 个最近的夹克,当某些内容发生更改时,它应该覆盖图像。

有谁知道如何解决这一问题?

4

1 回答 1

0

我解决了这个问题:

  def update
    if params.has_key?(:jacket)
      Recentjacket.update(params[:jacket].keys, params[:jacket].values)
      redirect_to '/recent'
    else
      redirect_to '/recent/edit',
        notice: 'No Files were selected to upload!' 
    end
  end
于 2013-12-18T10:30:31.020 回答