You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My photos upload and save fine, but when I call as_json I get an undefined method [] for nil class.
1.9.3p362 :009 > Photo.first.as_json
NoMethodError: undefined method `[]' for nil:NilClass
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:67:in `block in serializable_hash'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:66:in `each'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:66:in `serializable_hash'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/activemodel-3.2.11/lib/active_model/serializers/json.rb:96:in `as_json'
from (irb):9
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I have a simple Photo model
My photos upload and save fine, but when I call
as_json
I get an undefined method [] for nil class.Now, if I pass an empty hash, it works.
I think just changing the default argument in this method from nil to {} should fix it.
https://github.com/jnicklas/carrierwave-mongoid/blob/master/lib/carrierwave/mongoid.rb#L64
The text was updated successfully, but these errors were encountered: