rake aborted - 是nil:NilClass的目录/未定义方法`downcase'

时间:2013-04-29 11:34:42

标签: ruby-on-rails ruby-on-rails-3.2 mongoid3 dragonfly-gem

我有一个rake任务,通过dragonfly-gem将pdf从我的文件系统导入GridFS。任务失败,没有明显的原因。 我感谢任何帮助。谢谢!

佣金任务:

task :worksafety_files => :environment do
# Importiert Archiv-Dateien via Dragonfly in GridFS  
Worksafety.all.each do |worksafety|
  if worksafety.doc_1_tmp != nil and File.exist?("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_1_tmp}")
    worksafety.doc_1 = File.new("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_1_tmp}")
    worksafety.doc_1_tmp = nil
  end
  if worksafety.doc_2_tmp != nil and File.exist?("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_2_tmp}")
    worksafety.doc_2 = File.new("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_2_tmp}")
    worksafety.doc_2_tmp = nil
  end
  if worksafety.doc_3_tmp != nil and File.exist?("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_3_tmp}")
    worksafety.doc_3 = File.new("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_3_tmp}")
    worksafety.doc_3_tmp = nil
  end
  if File.exist?("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_4_tmp}")
    worksafety.doc_4 = File.new("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_4_tmp}")
    worksafety.doc_4_tmp = nil
  end
  if File.exist?("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_5_tmp}")
    worksafety.doc_5 = File.new("#{Rails.root}/config/mongify/archiv/safety/#{worksafety.doc_5_tmp}")
    worksafety.doc_5_tmp = nil
  end       

  worksafety.save
end
end

堆栈跟踪:

rake aborted!
Is a directory - read
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/temp_object.rb:198:in `copy_to_tempfile'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/temp_object.rb:100:in `tempfile'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/temp_object.rb:107:in `file'
....

我已经仔细检查了文件夹“safety”。其中只有pdf文件(使用文件-i *检查mime-tpye)。我认为这个问题与蜻蜓有关,因为当imagemagick在蜻蜓配置中被激活时...

app.configure_with(:imagemagick)

stacktrace是不同的:

rake aborted!
undefined method `downcase' for nil:NilClass
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-       08de999d19a0/lib/dragonfly/image_magick/utils.rb:26:in `identify'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/image_magick/analyser.rb:44:in `format'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/function_manager.rb:39:in `call'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/function_manager.rb:39:in `block (2 levels) in call_last'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/function_manager.rb:38:in `catch'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/function_manager.rb:38:in `block in call_last'
/home/vagrant/.rvm/gems/ruby-2.0.0-p0/bundler/gems/dragonfly-08de999d19a0/lib/dragonfly/function_manager.rb:37:in `each'
.....

2 个答案:

答案 0 :(得分:0)

破坏的正则表达式看起来像检查here

因为this段代码

format, width, height, depth全部设置为nil因为scan由于nil

而导致regex返回regex

修复{{1}}是我的建议,直到他们修复并修补它

希望这个帮助

答案 1 :(得分:0)

我在使用rake任务根据excel文档中的列导入图像时遇到此错误。我花了几分钟才意识到,如果文件名字段为空,则会产生错误。

我希望能帮助某人:)