NoMethodError(私有方法`gets'调用#<paperclip :: uploadedfileadapter:0xdbc7624>)</paperclip :: uploadedfileadapter:0xdbc7624>

时间:2012-04-29 22:38:14

标签: ruby-on-rails paperclip

我有这个方法:

  def parse_headers
    return unless upload?
    tempfile = upload.queued_for_write[:original]
    unless tempfile.nil?
      csv = CSV.new(tempfile, :headers => :first_row)
      csv.shift
      raise NilColumnHeader if csv.headers.include?(nil)
      self.headers = csv.headers
    end
  end

我得到了

NoMethodError (private method `gets' called for #<Paperclip::UploadedFileAdapter:0xdbc7624>):
  /home/neilmarion/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/csv.rb:1851:in `block in shift'
  /home/neilmarion/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/csv.rb:1849:in `loop'
  /home/neilmarion/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/csv.rb:1849:in `shift'
  app/models/import.rb:60:in `parse_headers'
  activesupport (3.2.3) lib/active_support/callbacks.rb:429:in `_run__820973538__save__162881384__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  activerecord (3.2.3) lib/active_record/callbacks.rb:264:in `create_or_update'
  activerecord (3.2.3) lib/active_record/persistence.rb:84:in `save'
  activerecord (3.2.3) lib/active_record/validations.rb:50:in `save'
  activerecord (3.2.3) lib/active_record/attribute_methods/dirty.rb:22:in `save'
  activerecord (3.2.3) lib/active_record/transactions.rb:241:in `block (2 levels) in save'
  activerecord (3.2.3) lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
  activerecord (3.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
  activerecord (3.2.3) lib/active_record/transactions.rb:208:in `transaction'
  deadlock_retry (1.2.0) lib/deadlock_retry.rb:31:in `transaction_with_deadlock_handling'
  activerecord (3.2.3) lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
  activerecord (3.2.3) lib/active_record/transactions.rb:241:in `block in save'
  activerecord (3.2.3) lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
  activerecord (3.2.3) lib/active_record/transactions.rb:240:in `save'
  app/controllers/imports_controller.rb:19:in `create'
  actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.3) lib/active_support/callbacks.rb:535:in `_run__450882913__process_action__213203411__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
  activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call'
  journey (1.0.3) lib/journey/router.rb:68:in `block in call'
  journey (1.0.3) lib/journey/router.rb:56:in `each'
  journey (1.0.3) lib/journey/router.rb:56:in `call'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
  omniauth (1.1.0) lib/omniauth/strategy.rb:177:in `call!'
  omniauth (1.1.0) lib/omniauth/strategy.rb:157:in `call'
  omniauth (1.1.0) lib/omniauth/strategy.rb:177:in `call!'
  omniauth (1.1.0) lib/omniauth/strategy.rb:157:in `call'
  /home/neilmarion/.rvm/gems/ruby-1.9.3-head@missionhub-p4/bundler/gems/rack-oauth2-server-96860b070f61/lib/rack/oauth2/server.rb:230:in `call'
  airbrake (3.0.9) lib/airbrake/rack.rb:27:in `call'
  client_side_validations (3.1.4) lib/client_side_validations/middleware.rb:18:in `call'
  warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
  warden (1.1.1) lib/warden/manager.rb:34:in `catch'
  warden (1.1.1) lib/warden/manager.rb:34:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.1) lib/rack/etag.rb:23:in `call'
  rack (1.4.1) lib/rack/conditionalget.rb:35:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__322488348__call__162881384__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  rails-dev-tweaks (0.6.1) lib/rails_dev_tweaks/granular_autoload/middleware.rb:34:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
  airbrake (3.0.9) lib/airbrake/user_informer.rb:12:in `call'
  railties (3.2.3) lib/rails/engine.rb:479:in `call'
  railties (3.2.3) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /home/neilmarion/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /home/neilmarion/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /home/neilmarion/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

可能是什么问题?感谢。

1 个答案:

答案 0 :(得分:3)

啊...... !!,我今天面临同样的问题

只需更改

upload.queued_for_write[:original] 

upload.queued_for_write[:original].read

并且有效