參數錯誤:使用參數時參數數量錯誤(2表示1)

[英]Argument Error: Wrong Number of Arguments (2 for 1) when using parameters


I've created parameters for an :image whitelist for a practice "pinboard" type application. Normally, the pin.rb would just call

我為實踐“pinboard”類型的應用程序創建了一個:圖像白名單的參數。通常,pin.rb會調用

attr_accessible :image

But Because it's Rails 4, I need to use strong parameters. As such, I've put them in the pins_controller.rb:

但因為它是Rails 4,我需要使用強參數。因此,我將它們放在pins_controller.rb中:

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

But when I try to upload an image (using paperclip), I get this error:

但是當我嘗試上傳圖像(使用回形針)時,我收到此錯誤:

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"}

I know that it has something to do with my parameters but I'm new to this and can't get it to work.

我知道它與我的參數有關,但我是新手,無法讓它工作。

1 个解决方案

#1


5  

Upgrading the paperclip to the most recent version should help:

將回形針升級到最新版本應該有助於:

gem "paperclip", "~> 3.5.1"

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/07/17/af607d5d7545e8ada8792b0bec9cf761.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com