Rails Paperclip gem错误的参数个数错误

时间:2013-02-17 20:56:25

标签: ruby-on-rails paperclip

我正在处理我的第一个RoR项目,并尝试使用Paperclip gem,但我遇到了一个我无法理解的错误:

  

错误的参数数量(1表示0)
  app / controllers / events_controller.rb:43:在`create'
  参数:

{"utf8"=>"✓",
 "authenticity_token"=>"OBYHA0M+TA93sNF3uqrJ/zvnnEyWJUREn4NcOl0ExfA=",
 "event"=>{"title"=>"",
 "image"=>#<ActionDispatch::Http::UploadedFile:0x007f803802b1f0 @original_filename="icon.png",
 @content_type="image/png",
 @headers="Content-Disposition: form-data; name=\"event[image]\"; filename=\"icon.png\"\r\nContent-Type: image/png\r\n",
 @tempfile=#<File:/tmp/RackMultipart20130217-21480-1molvwa>>,
 "description"=>"",
 "date"=>"",
 "time"=>""},
 "commit"=>"Create Event"}

据我所知,在create方法的events_controller.rb中,传入了太多的参数。但是,我遵循了Paperclip的Github上的QuickStart说明,所以我不确定为什么我会这样做。得到这个错误。

这是我的events_controller.rb代码

def create
    @event = Event.create( params[:event] )
 end

只是为了调试,我尝试将行更改为Event.create(params []),此时错误从错误的参数数量(1表示0)变为错误的参数数量(0表示1)。

这是我的event.rb代码

class Event < ActiveRecord::Base
    attr_accessible :date, :description, :time, :title, :image
    has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end

我已经检查过我为所有内容运行了正确的版本。我有Paperclip 3.4.0,Rails 3.2.12,Ruby 1.9.3和ImageMagick 6.8.3-1。我使用的是Ubuntu 12.04 LTS。

我看过很多类似的问题,但大多数似乎发生在几年前,并在随后的Paperclip更新中得到解决。我在类似帖子中发现的解决方案都没有为我工作,不幸的是我只有足够的Rails经验才知道发生了什么。我意识到我可能犯了一个全新的错误,在这种情况下我道歉但仍然非常感谢帮助我走上正轨。

如果有任何其他代码或信息对调试有用,请告诉我。

谢谢你的时间!

应用程序跟踪:

  

可卡因(0.3.2)lib / cocaine / command_line.rb:63:in run' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/helpers.rb:31:in run&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry_detector_factory.rb:18:in   block in geometry_string' activesupport (3.2.12) lib/active_support/core_ext/kernel/reporting.rb:43:in silence_stream&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry_detector_factory.rb:17:in   geometry_string' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry_detector_factory.rb:9:in 使&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry.rb:26:in   from_file' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/thumbnail.rb:35:in 初始化&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/processor.rb:33:in   new' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/processor.rb:33:in 使&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:431:in   block in post_process_style' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:430:in 各&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:430:in   inject' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:430:in post_process_style&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:423:in   block in post_process_styles' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:422:in 各&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:422:in   post_process&#39;中的post_process_styles' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:415:in 块(2级) activesupport(3.2.12)   LIB / active_support / callbacks.rb:403:在   _run__3384881169595487878__image_post_process__96086910066492375__callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:405:in __ run_callback&#39; activesupport(3.2.12)   LIB / active_support / callbacks.rb:385:在   _run_image_post_process_callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:81:in run_callbacks&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/callbacks.rb:26:in   post_process中的run_paperclip_callbacks' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:414:in 阻止&#39; activesupport(3.2.12)   LIB / active_support / callbacks.rb:403:在   _run__3384881169595487878__post_process__96086910066492375__callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:405:in __ run_callback&#39; activesupport(3.2.12)   lib / active_support / callbacks.rb:385:在_run_post_process_callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:81:in run_callbacks&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/callbacks.rb:26:in   run_paperclip_callbacks' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:413:in post_process&#39;   /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:108:in   has_attached_file&#39;中的assign' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip.rb:200:in阻止activerecord(3.2.12)   lib / active_record / attribute_assignment.rb:85:block in assign_attributes' activerecord (3.2.12) lib/active_record/attribute_assignment.rb:78:in每个&#39; ActiveRecord的   (3.2.12)lib / active_record / attribute_assignment.rb:78:in   assign_attributes' activerecord (3.2.12) lib/active_record/base.rb:497:in初始化&#39; activerecord(3.2.12)   lib / active_record / persistence.rb:44:在new' activerecord (3.2.12) lib/active_record/persistence.rb:44:in创建&#39;   app / controllers / events_controller.rb:43:在create' actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in send_action&#39; actionpack(3.2.12)   lib / abstract_controller / base.rb:167:在process_action' actionpack (3.2.12) lib/action_controller/metal/rendering.rb:10:in process_action&#39; actionpack(3.2.12)   lib / abstract_controller / callbacks.rb:18:in block in process_action' activesupport (3.2.12) lib/active_support/callbacks.rb:414:in 运行 _3332570171411252513__process_action_ 3320642634939127128 _callbacks&#39; activesupport(3.2.12)lib / active_support / callbacks.rb:405:in   __run_callback' activesupport (3.2.12) lib/active_support/callbacks.rb:385:in _ run_process_action_callbacks&#39;   activesupport(3.2.12)lib / active_support / callbacks.rb:81:in   run_callbacks' actionpack (3.2.12) lib/abstract_controller/callbacks.rb:17:in process_action&#39; ActionPack的   (3.2.12)lib / action_controller / metal / rescue.rb:29:在process_action' actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:30:in块中   process_action&#39; activesupport(3.2.12)   lib / active_support / notifications.rb:123:in block in instrument' activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in instrument&#39;   activesupport(3.2.12)lib / active_support / notifications.rb:123:in   instrument' actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:29:in process_action&#39;   actionpack(3.2.12)   lib / action_controller / metal / params_wrapper.rb:207:在process_action' activerecord (3.2.12) lib/active_record/railties/controller_runtime.rb:18:in process_action&#39; actionpack(3.2.12)   lib / abstract_controller / base.rb:121:在process' actionpack (3.2.12) lib/abstract_controller/rendering.rb:45:in进程&#39; ActionPack的   (3.2.12)lib / action_controller / metal.rb:203:在dispatch' actionpack (3.2.12) lib/action_controller/metal/rack_delegation.rb:14:in 发送&#39; actionpack(3.2.12)lib / action_controller / metal.rb:246:in   block in action' actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in呼叫&#39; ActionPack的   (3.2.12)lib / action_dispatch / routing / route_set.rb:73:在dispatch' actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:36:in 电话&#39;旅程(1.0.4)lib / journey / router.rb:68:block in call' journey (1.0.4) lib/journey/router.rb:56:in每个&#39;旅程(1.0.4)   lib / journey / router.rb:56:call' actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:601:in来电&#39; ActionPack的   (3.2.12)   lib / action_dispatch / middleware / best_standards_support.rb:17:in call' rack (1.4.5) lib/rack/etag.rb:23:in来电&#39;机架(1.4.5)   lib / rack / conditionalget.rb:35:in call' actionpack (3.2.12) lib/action_dispatch/middleware/head.rb:14:in来电&#39; ActionPack的   (3.2.12)lib / action_dispatch / middleware / params_parser.rb:21:在call' actionpack (3.2.12) lib/action_dispatch/middleware/flash.rb:242:in 电话&#39; rack(1.4.5)lib / rack / session / abstract / id.rb:210:in context' rack (1.4.5) lib/rack/session/abstract/id.rb:205:in call&#39; ActionPack的   (3.2.12)lib / action_dispatch / middleware / cookies.rb:341:在call' activerecord (3.2.12) lib/active_record/query_cache.rb:64:in电话&#39;   activerecord(3.2.12)   LIB / active_record / connection_adapters /抽象/ connection_pool.rb:479:在   call' actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:28:in阻止通话&#39;   activesupport(3.2.12)lib / active_support / callbacks.rb:405:in   _run__1281245379307539657__call__96086910066492375__callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:405:in __ run_callback&#39; activesupport(3.2.12)   lib / active_support / callbacks.rb:385:在_run_call_callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:81:in run_callbacks&#39; actionpack(3.2.12)   lib / action_dispatch / middleware / callbacks.rb:27:call' actionpack (3.2.12) lib/action_dispatch/middleware/reloader.rb:65:in来电&#39;   actionpack(3.2.12)lib / action_dispatch / middleware / remote_ip.rb:31:in   call' actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:16:in呼叫&#39;   actionpack(3.2.12)   lib / action_dispatch / middleware / show_exceptions.rb:56:in call' railties (3.2.12) lib/rails/rack/logger.rb:32:in call_app&#39; railties   (3.2.12)lib / rails / rack / logger.rb:16:in block in call' activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in已标记&#39; railties   (3.2.12)lib / rails / rack / logger.rb:16:in call' actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in call&#39;机架(1.4.5)   lib / rack / methodoverride.rb:21:在call' rack (1.4.5) lib/rack/runtime.rb:17:in来电&#39; activesupport(3.2.12)   lib / active_support / cache / strategy / local_cache.rb:72:in call' rack (1.4.5) lib/rack/lock.rb:15:in call&#39; actionpack(3.2.12)   lib / action_dispatch / middleware / static.rb:62:in call' railties (3.2.12) lib/rails/engine.rb:479:in call&#39;铁路(3.2.12)   lib / rails / application.rb:223:call' rack (1.4.5) lib/rack/content_length.rb:14:in来电&#39;铁路(3.2.12)   lib / rails / rack / log_tailer.rb:17:in call' rack (1.4.5) lib/rack/handler/webrick.rb:59:in service&#39;   /home/user/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/httpserver.rb:138:in   service' /home/user/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/httpserver.rb:94:in 运行&#39;   /home/user/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/server.rb:191:in   `阻止在start_thread&#39;

1 个答案:

答案 0 :(得分:4)

您使用的是可卡因的错误版本。运行bundle install,然后确保使用bundle exec rails s启动rails服务器。

较新版本的可卡因(〜> 0.4.0)中的run方法采用旧版本(0.3.2)没有的可选参数(def run(interpolations = {}))。

见上面的评论。