NoMethodError:未定义的方法`read' for nil:调用du.recreate_versions时的NilClass!(:some_version)

时间:2017-05-30 16:39:20

标签: carrierwave image-uploading image-upload

帮助。 CarrierWave的receate_versions!并不适合我。 Carrierwave版本:1.1.0。代码:

# document_image_uploader.rb

  ...
  version :some_version, if: :image? do
    process :resize_to_fit => [2048, 2048]
  end

  # See http://stackoverflow.com/a/30897174/590767
  def image?(new_file)
    new_file.content_type.start_with? 'image'
  end

在控制台中:

> du = DocumentImageUploader.new # this is a CarrierWave::Uploader::Base subclass

> du.recreate_versions!(:some_version)
NoMethodError: undefined method `read' for nil:NilClass
    from ~/.rvm/gems/ruby-2.2.7/gems/carrierwave-1.1.0/lib/carrierwave/uploader/cache.rb:81:in `sanitized_file'
    from ~/.rvm/gems/ruby-2.2.7/gems/carrierwave-1.1.0/lib/carrierwave/uploader/versions.rb:224:in `recreate_versions!'
    from (irb):5
    from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
    from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
    from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
    from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:8:in `require'
    from bin/rails:8:in `<main>'

还在该项目的GitHub问题上写了它:

https://github.com/carrierwaveuploader/carrierwave/issues/2186

0 个答案:

没有答案