Skip to content

Instantly share code, notes, and snippets.

@scottjbarr
Created November 2, 2009 01:27
Show Gist options
  • Save scottjbarr/223866 to your computer and use it in GitHub Desktop.
Save scottjbarr/223866 to your computer and use it in GitHub Desktop.
Mongoid error on save
require 'mongoid'
class Person < Mongoid::Document
field :title
field :name
field :age
has_many :addresses
end
class Address < Mongoid::Document
field :street
field :city
field :state
field :post_code
belongs_to :person
end
Mongoid.connect_to("mongoid-test")
person = Person.new(:title => 'Mr', :name => 'Guy Mandood', :age => 22)
person.save!
a = Address.new
a.street = 'Orchard Rd'
a.city = 'Singapore'
a.state = 'Singapore'
a.person = person
a.save! # Exception here, see below
#/usr/local/lib/ruby19/gems/1.9.1/gems/mongoid-0.6.1/lib/mongoid/commands/save.rb:16:in `execute': undefined method #`save' for nil:NilClass (NoMethodError)
# from /usr/local/lib/ruby19/gems/1.9.1/gems/mongoid-0.6.1/lib/mongoid/commands.rb:55:in `save!'
# from ./mongoid_test.rb:30:in `<main>'
@scottjbarr
Copy link
Author

scottjbarr commented May 27, 2011 via email

@RooSoft
Copy link

RooSoft commented May 27, 2011 via email

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