Skip to content

Instantly share code, notes, and snippets.

@wflanagan
Created January 15, 2012 13:16
Show Gist options
  • Save wflanagan/1615835 to your computer and use it in GitHub Desktop.
Save wflanagan/1615835 to your computer and use it in GitHub Desktop.
I am having a problem adding a hash to an Existing Mongoid Document
class Entity
include Mongoid::Document
#normal fields
scores, :type => Hash, :default => {}
def fix_scores
self.scores = {} if scores.nil?
self.save
end
end
@wflanagan
Copy link
Author

I have tried it with and without the default declaration, no difference. The error is:

a.scores = {}
NoMethodError: undefined method set' for {}:Hash from /Users/wflanagan/sites/marketfu/vendor/bundle/bundler/gems/mongoid-7b3cfd92c5ab/lib/mongoid/field.rb:45:inset'
from /Users/wflanagan/sites/marketfu/vendor/bundle/bundler/gems/mongoid-7b3cfd92c5ab/lib/mongoid/attributes.rb:111:in `write_attribute'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment