参数错误:使用参数时参数数量错误(2表示1)

时间:2013-07-17 01:25:06

标签: ruby-on-rails ruby paperclip

我为实践“插板”类型的应用程序创建了:图像白名单的参数。通常,pin.rb只会调用

attr_accessible :image

但是因为它是Rails 4,我需要使用强参数。因此,我将它们放在pins_controller.rb中:

def pin_params
  params.require(:pin).permit(:description, :image)
end

但是当我尝试上传图片时(使用回形针),我收到了这个错误:

ArgumentError in PinsController#create
wrong number of arguments (2 for 1)

Extracted source (around line #29):
27
28
29
30
31
32

  # POST /pins.json
  def create
    @pin = current_user.pins.new(pin_params)

    respond_to do |format|
      if @pin.save

Rails.root: /Users/michaeljdionne/Projects/Rails/omrails

Application Trace | Framework Trace | Full Trace
app/controllers/pins_controller.rb:29:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"awnx8EwrnA/ZoFIBe+ClL6wPbJ+sYnmTvwBCmzNmCHM=",
 "pin"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fa4ab3796a8 @tempfile=#<File:/var/folders/39/00kqhhp14v9ddj0hrvg9_9bm0000gn/T/RackMultipart20130716-43150-1cflb9r>,
 @original_filename="IMG_0401.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"pin[image]\"; filename=\"IMG_0401.jpg\"\r\nContent-Type: image/jpeg\r\n">,
 "description"=>"asd"},
 "commit"=>"Create Pin"}

我知道它与我的参数有关,但我是新手,无法让它发挥作用。

1 个答案:

答案 0 :(得分:6)

将回形针升级到最新版本应该会有所帮助:

gem "paperclip", "~> 3.5.1"