Created
January 15, 2012 13:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Entity | |
include Mongoid::Document | |
#normal fields | |
scores, :type => Hash, :default => {} | |
def fix_scores | |
self.scores = {} if scores.nil? | |
self.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:in
set'from /Users/wflanagan/sites/marketfu/vendor/bundle/bundler/gems/mongoid-7b3cfd92c5ab/lib/mongoid/attributes.rb:111:in `write_attribute'