Rails的回形针宝石错号码参数错误
我的工作我的第一个项目的回报率,并尝试使用回形针宝石,但我遇到了一个错误,我似乎无法弄清楚的:Rails的回形针宝石错号码参数错误
wrong number of arguments (1 for 0)
app/controllers/events_controller.rb:43:in `create'
Parameters:
{"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中,太多的参数被传入。但是,我遵循回形针的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。
我已经看了不少类似的问题,但大多数似乎在几年前发生,并在后续更新回形针中得到解决。我在类似帖子中找到的解决方案都没有为我工作,不幸的是,我只是有足够的Rails经验,知道发生了什么。我意识到我可能犯了一个总的新手错误,在这种情况下,我表示歉意,但仍然真的很感谢帮助我走上正轨。
请让我知道,如果任何额外的代码或信息将有助于调试。
谢谢你的时间!
应用跟踪:
cocaine (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' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry_detector_factory.rb:18:inblock in geometry_string' activesupport (3.2.12) lib/active_support/core_ext/kernel/reporting.rb:43:in
silence_stream' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry_detector_factory.rb:17:ingeometry_string' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry_detector_factory.rb:9:in
make' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/geometry.rb:26:infrom_file' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/thumbnail.rb:35:in
initialize' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/processor.rb:33:innew' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/processor.rb:33:in
make' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:431:inblock in post_process_style' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:430:in
each' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:430:ininject' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:430:in
post_process_style' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:423:inblock in post_process_styles' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:422:in
each' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:422:inpost_process_styles' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:415:in
block (2 levels) in post_process' activesupport (3.2.12) lib/active_support/callbacks.rb:403:in_run__3384881169595487878__image_post_process__96086910066492375__callbacks' 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_image_post_process_callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:81:in
run_callbacks' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/callbacks.rb:26:inrun_paperclip_callbacks' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:414:in
block in post_process' activesupport (3.2.12) lib/active_support/callbacks.rb:403:in_run__3384881169595487878__post_process__96086910066492375__callbacks' 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_post_process_callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:81:in
run_callbacks' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/callbacks.rb:26:inrun_paperclip_callbacks' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:413:in
post_process' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip/attachment.rb:108:inassign' /home/user/.rvm/gems/ruby-1.9.3-p385/bundler/gems/paperclip-dcd2774e7913/lib/paperclip.rb:200:in
block in has_attached_file' activerecord (3.2.12) lib/active_record/attribute_assignment.rb:85:inblock in assign_attributes' activerecord (3.2.12) lib/active_record/attribute_assignment.rb:78:in
each' activerecord (3.2.12) lib/active_record/attribute_assignment.rb:78:inassign_attributes' activerecord (3.2.12) lib/active_record/base.rb:497:in
initialize' activerecord (3.2.12) lib/active_record/persistence.rb:44:innew' activerecord (3.2.12) lib/active_record/persistence.rb:44:in
create' app/controllers/events_controller.rb:43:increate' actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in
send_action' actionpack (3.2.12) lib/abstract_controller/base.rb:167:inprocess_action' actionpack (3.2.12) lib/action_controller/metal/rendering.rb:10:in
process_action' actionpack (3.2.12) lib/abstract_controller/callbacks.rb:18:inblock in process_action' activesupport (3.2.12) lib/active_support/callbacks.rb:414:in
run_3332570171411252513__process_action_3320642634939127128_callbacks' 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' activesupport (3.2.12) lib/active_support/callbacks.rb:81:inrun_callbacks' actionpack (3.2.12) lib/abstract_controller/callbacks.rb:17:in
process_action' actionpack (3.2.12) lib/action_controller/metal/rescue.rb:29:inprocess_action' actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:30:in
block in process_action' activesupport (3.2.12) lib/active_support/notifications.rb:123:inblock in instrument' activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in
instrument' activesupport (3.2.12) lib/active_support/notifications.rb:123:ininstrument' actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:29:in
process_action' actionpack (3.2.12) lib/action_controller/metal/params_wrapper.rb:207:inprocess_action' activerecord (3.2.12) lib/active_record/railties/controller_runtime.rb:18:in
process_action' actionpack (3.2.12) lib/abstract_controller/base.rb:121:inprocess' actionpack (3.2.12) lib/abstract_controller/rendering.rb:45:in
process' actionpack (3.2.12) lib/action_controller/metal.rb:203:indispatch' actionpack (3.2.12) lib/action_controller/metal/rack_delegation.rb:14:in
dispatch' actionpack (3.2.12) lib/action_controller/metal.rb:246:inblock in action' actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in
call' actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:indispatch' actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:36:in
call' journey (1.0.4) lib/journey/router.rb:68:inblock in call' journey (1.0.4) lib/journey/router.rb:56:in
each' journey (1.0.4) lib/journey/router.rb:56:incall' actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:601:in
call' actionpack (3.2.12) lib/action_dispatch/middleware/best_standards_support.rb:17:incall' rack (1.4.5) lib/rack/etag.rb:23:in
call' rack (1.4.5) lib/rack/conditionalget.rb:35:incall' actionpack (3.2.12) lib/action_dispatch/middleware/head.rb:14:in
call' actionpack (3.2.12) lib/action_dispatch/middleware/params_parser.rb:21:incall' actionpack (3.2.12) lib/action_dispatch/middleware/flash.rb:242:in
call' rack (1.4.5) lib/rack/session/abstract/id.rb:210:incontext' rack (1.4.5) lib/rack/session/abstract/id.rb:205:in
call' actionpack (3.2.12) lib/action_dispatch/middleware/cookies.rb:341:incall' activerecord (3.2.12) lib/active_record/query_cache.rb:64:in
call' activerecord (3.2.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:incall' actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:28:in
block in call' 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' activesupport (3.2.12) lib/active_support/callbacks.rb:385:in_run_call_callbacks' activesupport (3.2.12) lib/active_support/callbacks.rb:81:in
run_callbacks' actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (3.2.12) lib/action_dispatch/middleware/reloader.rb:65:in
call' actionpack (3.2.12) lib/action_dispatch/middleware/remote_ip.rb:31:incall' actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:16:in
call' actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:incall' railties (3.2.12) lib/rails/rack/logger.rb:32:in
call_app' railties (3.2.12) lib/rails/rack/logger.rb:16:inblock in call' activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in
tagged' railties (3.2.12) lib/rails/rack/logger.rb:16:incall' actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in
call' rack (1.4.5) lib/rack/methodoverride.rb:21:incall' rack (1.4.5) lib/rack/runtime.rb:17:in
call' activesupport (3.2.12) lib/active_support/cache/strategy/local_cache.rb:72:incall' rack (1.4.5) lib/rack/lock.rb:15:in
call' actionpack (3.2.12) lib/action_dispatch/middleware/static.rb:62:incall' railties (3.2.12) lib/rails/engine.rb:479:in
call' railties (3.2.12) lib/rails/application.rb:223:incall' rack (1.4.5) lib/rack/content_length.rb:14:in
call' railties (3.2.12) lib/rails/rack/log_tailer.rb:17:incall' rack (1.4.5) lib/rack/handler/webrick.rb:59:in
service' /home/user/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/httpserver.rb:138:inservice' /home/user/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/httpserver.rb:94:in
run' /home/user/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
您正在使用可卡因的版本错误。运行bundle install
,然后确保您使用的是bundle exec rails s
来启动您的Rails服务器。
可卡因新版本(〜> 0.4.0)中的运行方法采用旧版本(0.3.2)没有的可选参数(def run(interpolations = {})
)。
请参阅上面的注释。
感谢您的帮助。这解决了我得到的错误。由于ImageMagick的错误,我故意回滚到可卡因0.3.2:“[paperclip]处理时收到错误:#
我能够解决第二个错误:我已经从他们的网站上列出的来源构建ImageMagick。它自己安装到/ usr/local/bin,并且我已经将该路径添加到我的/config/environments/development.rb文件中,如Paperclip所述。为了修复NotIdentifiedByImageMagicError,我完全卸载了ImageMagick,而不是进行make install,我做了一个sudo apt-get install imagemagick,它安装到/ usr/bin。我更新了我的development.rb文件以反映:(Paperclip.options [:command_path] =“/ usr/bin /”),重新启动了我的服务器,并解决了问题。 – bmyers 2013-02-22 16:19:46
不客气!很高兴你能够得到它的工作。 – nates 2013-02-22 17:53:24
“image”=>#>很奇怪,你能再次检查一下,如果这真的是输出吗? – MoMolog 2013-02-17 20:59:55
嗨,对不起,我认为在输出中有一个转义字符,它正在删除一堆消息。我把它放在一个代码块中,现在就在这里。但是#仍然在那里。 – bmyers 2013-02-17 21:25:08
如果在事件模型中添加“包含Paperclip :: Glue”会怎样? – nates 2013-02-17 22:45:20