title: Undefined method for a model with Ruby on Rails and MongoDB?
body: <p>I am getting started with a non-SQL database (specifically, MongoDB) and Ruby on Rails because I believe flexible schemas will be an advantage.  Right now, I'm confused because some things I expect to "just work" aren't working.  Specifically, I have a "method missing" error on one of my pages.</p>
  
  <pre><code>NoMethodError in Users#new
  
  undefined method `email' for #&lt;User _id: BSON::ObjectId('4eb8cbcaef704c02da000017')&gt;
  
  Extracted source (around line #13):
  
  10:       &lt;tbody&gt;&lt;tr&gt;
  11:         &lt;td&gt;&lt;%= f.label :email %&gt;:&lt;/td&gt;
  12:         &lt;td&gt;
  13:           &lt;%= f.text_field :email, :placeholder =&gt; "your email address" %&gt;
  14:         &lt;/td&gt;
  15:       &lt;/tr&gt;
  16:       &lt;tr&gt;
  </code></pre>
  
  <p>In the console:</p>
  
  <pre><code>&gt;&gt; User.new.email
  NoMethodError: undefined method `email' for #&lt;User _id: BSON::ObjectId('4eb8cc4def704c0358000005')&gt;
      from /Library/Ruby/Gems/1.8/gems/activemodel-3.1.1/lib/active_model/attribute_methods.rb:385:in `method_missing'
      from (irb):5
  </code></pre>
  
  <p>The model looks like: (note class User does not inherit from any Active Record super class... does this matter?)</p>
  
  <pre><code>class User
    include MongoMapper::Document
  
    attr_accessor :password
    attr_accessible :username, :email, :password
  
    email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  
    validates :username, :presence =&gt; true,
                     :format =&gt; { :with =&gt; /^[a-zA-Z][a-zA-Z0-9_]+$/ },
                     :length =&gt; { :maximum =&gt; 32, :minimum =&gt; 4 }
    validates :email, :presence =&gt; true,
                      :format =&gt; { :with =&gt; email_regex },
                      :uniqueness =&gt; { :case_sensitive =&gt; false }
    validates :password, :presence =&gt; true,
                         :length =&gt; { :within =&gt; 5..32 },
                         :confirmation =&gt; true
    (etc...)
  </code></pre>