2

我已经为练习“pinboard”类型应用程序的 :image 白名单创建了参数。通常, 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"}

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

4

1 回答 1

6

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

gem "paperclip", "~> 3.5.1"
于 2013-09-04T12:38:55.253 回答