适用于actionDispatch的carrierwave的参数数量错误

时间:2014-03-05 23:33:57

标签: ruby-on-rails carrierwave

我的Paintings_controller错误数量的参数错误(2表示0)。

 def create
@painting = Painting.new(painting_params)

我正在使用Carrierwave我有一个使用Carrierwave的其他控制器(Attachements_controller),但它没有错误。 我想知道为什么对于“图像”字段它没有像附件字段{“数据”

的数组{}

paintings_controller  "image"=>#<ActionDispatch::Http::UploadedFile:0x0000000456bc98 @tempfile=#<Tempfile:/tmp/RackMultipart20140305-28010-vof7in>

attachement_controller

  "attachment"=>{"data"=>#<ActionDispatch::Http::UploadedFile:0x0000000096d728 @tempfile=#<Tempfile:/tmp/RackMultipart20140305-27719-1lw9xcn>,
 @original_filename="tumblr_mvhfvfHyWV1qkkdlto1_1280.jpg",

日志

Started POST "/paintings" for 127.0.0.1 at 2014-03-05 18:17:00 -0500
Processing by PaintingsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"pyZdz9eqYiEW+yEsXWy0gjh2o3UwA+AiwhAqxe98xHE=", "painting"=>{"title"=>"asdfa", "date(1i)"=>"2014", "date(2i)"=>"3", "date(3i)"=>"5", "dimension"=>"asfd", "medium"=>"asdfa", "image"=>#<ActionDispatch::Http::UploadedFile:0x0000000456bc98 @tempfile=#<Tempfile:/tmp/RackMultipart20140305-28010-vof7in>, @original_filename="tumblr_mmh9dpWBPb1qkkdlto1_500.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"painting[image]\"; filename=\"tumblr_mmh9dpWBPb1qkkdlto1_500.jpg\"\r\nContent-Type: image/jpeg\r\n">, "description"=>"asdfaf"}, "commit"=>"Create Painting"}
Completed 500 Internal Server Error in 62ms

ArgumentError (wrong number of arguments (2 for 0)):
  app/controllers/paintings_controller.rb:27:in `create'

绘画参数

{"utf8"=>"✓",
 "authenticity_token"=>"pyZdz9eqYiEW+yEsXWy0gjh2o3UwA+AiwhAqxe98xHE=",
 "painting"=>{"title"=>"asdfa",
 "date(1i)"=>"2014",
 "date(2i)"=>"3",
 "date(3i)"=>"5",
 "dimension"=>"asfd",
 "medium"=>"asdfa",
 "image"=>#<ActionDispatch::Http::UploadedFile:0x0000000456bc98 @tempfile=#<Tempfile:/tmp/RackMultipart20140305-28010-vof7in>,
 @original_filename="tumblr_mmh9dpWBPb1qkkdlto1_500.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"painting[image]\"; filename=\"tumblr_mmh9dpWBPb1qkkdlto1_500.jpg\"\r\nContent-Type: image/jpeg\r\n">,
 "description"=>"asdfaf"},
 "commit"=>"Create Painting"}

附件参数

{"utf8"=>"✓",
 "authenticity_token"=>"K+mAtKBR0YJjfab28H4ecmTBL2AarqkPr3mHdgl9EQ4=",
 "attachment"=>{"data"=>#<ActionDispatch::Http::UploadedFile:0x0000000096d728 @tempfile=#<Tempfile:/tmp/RackMultipart20140305-27719-1lw9xcn>,
 @original_filename="tumblr_mvhfvfHyWV1qkkdlto1_1280.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"attachment[data]\"; filename=\"tumblr_mvhfvfHyWV1qkkdlto1_1280.jpg\"\r\nContent-Type: image/jpeg\r\n">},
 "commit"=>"Create Attachment"}

def painting_params
      params.require(:painting).permit(:title, :date, :dimension, :medium, :image, :description)
    end

1 个答案:

答案 0 :(得分:1)

替换

version :thumb do 
process :thumb => [100, 100] 
end 

version :thumb do 
process :resize_to_fit => [100, 100] 
end

设置image

时出现问题
lib/carrierwave/mount.rb:179:in `image='  ## in stacktrace