title: virtual field in a model part of the model but not in the DB
body: <p>I have a standard model with a few fields that are saved to a DB, and I need 1 field that doesn't have to be saved.</p>
  
  <p>I tried attr_accessor but that doesn't cover it. Using Attr_accessor I can set and get the field, but it is not part of the model. If I add the models to an array and then see what is in the virtual field is not part of it. I also tried to add the field :headerfield to attr_accessible but that didn't change anything.</p>
  
  <p>How can I get a field that is part of the model but not saved to the database?</p>
  
  <p>The model</p>
  
  <pre><code>class Mapping &lt; ActiveRecord::Base
    attr_accessible :internalfield, :sourcefield
    attr_accessor :headerfield
  end
  </code></pre>
  
  <p>console output:</p>
  
  <pre><code>1.9.3-p194 :001 &gt; m = Mapping.new
   =&gt; #&lt;Mapping id: nil, internalfield: nil, sourcefield: nil, created_at: nil, updated_at: nil, data_set_id: nil&gt;
  1.9.3-p194 :002 &gt; m.headerfield = "asef"
   =&gt; "asef"
  1.9.3-p194 :003 &gt; m
   =&gt; #&lt;Mapping id: nil, internalfield: nil, sourcefield: nil, created_at: nil, updated_at: nil, data_set_id: nil&gt;
  </code></pre>