title: Dynamic attributes with Rails and Mongoid
body: <p>I'm learning MongoDB through the Mongoid Ruby gem with Rails (Rails 3 beta 3), and I'm trying to come up with a way to create dynamic attributes on a model based on fields from another model, which I thought a schema-less database would be a good choice for.</p>
  
  <p>So for example, I'd have the models:</p>
  
  <pre><code>class Account
    include Mongoid::Document
  
    field :name, :type =&gt; String
    field :token, :type =&gt; String
    field :info_needed, :type =&gt; Array
  
    embeds_many :members
  end
  
  class Member
    include Mongoid::Document
  
    embedded_in :account, :inverse_of =&gt; :members
  
  end
  </code></pre>
  
  <p>I'm looking to take the "info_needed" attribute of the Account model and created dynamic attributes on the Member model based on what's inside.  If club.info_needed was ["first_name", "last_name"], I'm trying to create a form that would save first_name and last_name attributes to the Member model.</p>
  
  <p>However, upon practice, I just keep getting "undefined method first_name=" errors on the Member model when trying to do this.  I know MongoDB can handle dynamic attributes per record, but how can I get Mongoid to do this without an undefined method error?</p>