出乎意料的是,当我尝试使用Carrerwave和Fog将照片上传到我的应用时,我开始收到以下错误。它工作得很好:
NoMethodError (undefined method `content_length' for nil:NilClass)
这是我第一次收到错误,只有在使用雾存储时才会发生。我认为它可能与缓存与照片相关的用户模型有关,但我暂时关闭缓存并且问题仍然存在。它似乎与this problem last commented on 8 days ago有关。
问题发生在我的应用程序中,甚至在尝试保存后在我的Rails控制台中发生:
u = User.new
u.photo = File.open('somewhere.jpg')
u.save!
(0.4ms) ROLLBACK
NoMethodError: undefined method `content_length' for nil:NilClass
这是完整的痕迹
NoMethodError: undefined method `content_length' for nil:NilClass
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:239:in `size'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/uploader/proxy.rb:57:in `size'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/sanitized_file.rb:96:in `size'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/sanitized_file.rb:136:in `empty?'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/uploader/cache.rb:119:in `cache!'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:329:in `cache'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:163:in `photo='
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/carrierwave-0.10.0/lib/carrierwave/orm/activerecord.rb:39:in `photo='
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:345:in `block in previous_model'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:344:in `each_pair'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:344:in `previous_model'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:260:in `block (2 levels) in _update_counts_after_update'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:257:in `each'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:257:in `block in _update_counts_after_update'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:229:in `call'
from /Users/paulosetinsky/.rvm/gems/ruby-2.1.1/gems/counter_culture-0.1.30/lib/counter_culture.rb:229:in `_wrap_in_counter_culture_active'
感谢任何帮助!