Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2958

creating or saving new objects fail with 'wrong arguments 1 for 0....'

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.4
    • Affects Version/s: None
    • Component/s: None
    • None

      On Mongoid 3.1.2 with bson & bson-ext version 1.8.4 , I am unable to create or save a new model object in the rails console or in the web application. Any insight on how to fix this would be appreciated. Here is a snippet that shows my errors from both attempts.

      Loading development environment (Rails 3.2.0)
      ruby-1.9.3-head :001 > g = Game.new
      => #<Game _id: 51667a2e9459a77d39000001, created_at: nil, updated_at: nil, creator: nil, facebook_id: nil, status_id: nil>
      ruby-1.9.3-head :002 > g.creator = 'me'
      ArgumentError: wrong number of arguments (1 for 0)
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/extensions/object.rb:134:in `mongoize'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/fields/standard.rb:10:in `mongoize'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes.rb:345:in `typed_value_for'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes.rb:183:in `block in write_attribute'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/threaded/lifecycle.rb:26:in `_assigning'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes.rb:180:in `write_attribute'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/fields.rb:436:in `block (2 levels) in create_field_setter'
      from (irb):2
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
      from script/rails:6:in `require'
      from script/rails:6:in `<main>'
      ruby-1.9.3-head :003 > g2 = Game.new(

      {creator: 'me'}

      )
      ArgumentError: wrong number of arguments (1 for 0)
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/extensions/object.rb:134:in `mongoize'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/fields/standard.rb:10:in `mongoize'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes.rb:345:in `typed_value_for'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes.rb:183:in `block in write_attribute'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/threaded/lifecycle.rb:26:in `_assigning'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes.rb:180:in `write_attribute'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/fields.rb:436:in `block (2 levels) in create_field_setter'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes/processing.rb:127:in `process_attribute'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes/processing.rb:28:in `block (2 levels) in process_attributes'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes/processing.rb:26:in `each_pair'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes/processing.rb:26:in `block in process_attributes'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes/processing.rb:193:in `with_mass_assignment'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/attributes/processing.rb:22:in `process_attributes'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/document.rb:94:in `block in initialize'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/threaded/lifecycle.rb:84:in `_building'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/mongoid-3.1.2/lib/mongoid/document.rb:89:in `initialize'
      from (irb):3:in `new'
      from (irb):3
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
      from /Users/calvinimac/.rvm/gems/ruby-1.9.3-head@3.2.0/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
      from script/rails:6:in `require'
      from script/rails:6:in `<main>'ruby-1.9.3-head :004 > quit

      // Environment
      Environment wise, I'm on OSX (Mountain Lion) running mongodb version 2.4. I am using ruby 1.9.3p411 with rails 3.2.0. Here is my compete gems listing from 'bundle show':
      actionmailer (3.2.0)

      • actionpack (3.2.0)
      • activemodel (3.2.0)
      • activerecord (3.2.0)
      • activeresource (3.2.0)
      • activesupport (3.2.0)
      • addressable (2.3.3)
      • angularjs-rails (1.0.5)
      • arel (3.0.2)
      • awesome_print (1.1.0)
      • better_errors (0.3.2)
      • binding_of_caller (0.6.8)
      • bson (1.8.4)
      • bson_ext (1.8.4)
      • builder (3.0.4)
      • bundler (1.3.5)
      • coderay (1.0.8)
      • coffee-rails (3.2.2)
      • coffee-script (2.2.0)
      • coffee-script-source (1.6.2)
      • daemons (1.1.9)
      • erubis (2.7.0)
      • eventmachine (1.0.0)
      • execjs (1.4.0)
      • faraday (0.8.7)
      • hike (1.2.1)
      • i18n (0.6.4)
      • journey (1.0.4)
      • jquery-rails (1.0.19)
      • json (1.7.7)
      • koala (1.6.0)
      • mail (2.4.4)
      • mime-types (1.22)
      • mongoid (3.1.2)
      • moped (1.4.5)
      • multi_json (1.7.2)
      • multipart-post (1.2.0)
      • origin (1.0.11)
      • polyglot (0.3.3)
      • rack (1.4.5)
      • rack-cache (1.2)
      • rack-ssl (1.3.3)
      • rack-test (0.6.2)
      • rails (3.2.0)
      • railties (3.2.0)
      • rake (10.0.4)
      • rdoc (3.12.2)
      • sass (3.2.7)
      • sass-rails (3.2.6)
      • sprockets (2.1.3)
      • thin (1.5.0)
      • thor (0.14.6)
      • tilt (1.3.6)
      • treetop (1.4.12)
      • tzinfo (0.3.37)
      • uglifier (2.0.1)

      // ODM - Details of Classes and their Document
      I have some simple classes as shown below:

      class Game
        include Mongoid::Document
        include Mongoid::Timestamps
      
        embeds_many :questions
        embeds_many :players
      
        field :creator, :type => :String
        field :status_id, :type => :Integer
      end
      
      class Question
        include Mongoid::Document
      
        #embeds_many :choices
        embedded_in :game
      
        field :question, :type => :String
        field :answer, :type => :String
        field :choices, :type => Array
      end
      
      class Player
        include Mongoid::Document
      
        embedded_in :game
      
        field :name, :type => :String
        field :facebook_id, :type => :String
      end
      

      If I use mongoid 2.4.0, I'm able to get farther along but would rather gain the benefits of the 3.x versions. I've spent a good amount of time debugging and feel like I'm badly missing something.

      -Thanks for reading through this.

            Assignee:
            durran Durran Jordan
            Reporter:
            calirails calirails
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: