Skip to content

Instantly share code, notes, and snippets.

@jjcall
Created January 20, 2014 20:19
Show Gist options
  • Save jjcall/8528256 to your computer and use it in GitHub Desktop.
Save jjcall/8528256 to your computer and use it in GitHub Desktop.
Problem:
Attempted to set a value for 'name' which is not allowed on the model User.
Summary:
Without including Mongoid::Attributes::Dynamic in your model and the attribute does not already exist in the attributes hash, attempting to call User#name= for it is not allowed. This is also triggered by passing the attribute to any method that accepts an attributes hash, and is raised instead of getting a NoMethodError.
Resolution:
You can include Mongoid::Attributes::Dynamic if you expect to be writing values for undefined fields often.
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/attributes/processing.rb:96:in `process_attribute'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/attributes/processing.rb:25:in `block in process_attributes'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/attributes/processing.rb:23:in `each_pair'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/attributes/processing.rb:23:in `process_attributes'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/document.rb:112:in `block in initialize'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/threaded/lifecycle.rb:84:in `_building'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/document.rb:106:in `initialize'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/criteria/modifiable.rb:147:in `new'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/criteria/modifiable.rb:147:in `create_document'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/criteria/modifiable.rb:19:in `build'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/criteria/modifiable.rb:168:in `find_or'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/criteria/modifiable.rb:81:in `find_or_initialize_by'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bundler/gems/mongoid-9b3bc1264032/lib/mongoid/findable.rb:15:in `find_or_initialize_by'
/Users/jjco/Projects/Javelin/QuickMVP/quickmvp/lib/tasks/load_dev_data.rake:3:in `block in <top (required)>'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bin/ruby_executable_hooks:15:in `eval'
/Users/jjco/.rvm/gems/ruby-2.0.0-p0@quickmvp/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => load_dev_data
(See full trace by running task with --trace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment