jnicklas/carrierwave — Issue #555: "TypeError: can't convert nil into String" while saving/updating using GridFS
Author: eraserewind
Created: 2011-12-12 16:22:05+00:00
State: open

Hi. Rails 3.1.1, Ruby 1.9.1-p0, CarrierWave 0.5.8 with carrierwave-mongoid.

Here's what I got while saving :

ruby-1.9.3-p0 :012 > t = TrackedAsset.edit("4edaad3814d0fe7d5a000001")
[snip]
ruby-1.9.3-p0 :013 > t.avatar = File.new("#{Rails.root}/tmp/xhr_uploads/7c2ee8eaed903b860f94_cni.png", 'r')
=> #
ruby-1.9.3-p0 :018 > t.save
TypeError: can't convert nil into String
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/carrierwave-0.5.8/lib/carrierwave/uploader/url.rb:18:in `expand_path'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/carrierwave-0.5.8/lib/carrierwave/uploader/url.rb:18:in `url'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/carrierwave-0.5.8/lib/carrierwave/uploader/versions.rb:164:in `url'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/carrierwave-0.5.8/lib/carrierwave/uploader/default_url.rb:8:in `url'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/carrierwave-0.5.8/lib/carrierwave/uploader/url.rb:30:in `as_json'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:55:in `block in as_json'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:78:in `check_for_circular_references'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:54:in `as_json'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `block in as_json'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `each'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `map'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `as_json'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:55:in `block in as_json'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:78:in `check_for_circular_references'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:54:in `as_json'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/json/encoding.rb:245:in `block in as_json'
... 33 levels...
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:421:in `_run_save_callbacks'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/activesupport-3.1.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/callbacks.rb:42:in `block in run_callbacks'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/callbacks.rb:67:in `call'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/callbacks.rb:67:in `run_cascading_callbacks'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/callbacks.rb:41:in `run_callbacks'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/persistence/modification.rb:23:in `prepare'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/persistence/operations/update.rb:43:in `persist'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/persistence.rb:86:in `update'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@console/gems/mongoid-2.3.4/lib/mongoid/persistence.rb:151:in `upsert'
from (irb):18
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /Users/erase/.rvm/gems/ruby-1.9.3-p0@global/gems/railties-3.1.1/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'

I also got the error multiple times while creating documents, randomly.