title: Check for nested attributes in before_save
body: <p>When you submit a form to the controller for saving in ActiveRecord, you can add missing fields via <code>@foo.field = 'bar'</code>. I would like to do the same thing for a nested attribute, but I cannot figure out how. </p>
  
  <p>I am trying to do something like:</p>
  
  <pre><code>'@foo.bar.field = 'baz'
  </code></pre>
  
  <p>where the foo model</p>
  
  <pre><code>accepts_nested_attributes_for :bar
  </code></pre>
  
  <p>if that makes more sense. </p>
  
  <p>Edit: relevant model code</p>
  
  <pre><code>class Product &lt; ActiveRecord::Base
    ...  
  
    has_many :update
  
    belongs_to :user, :foreign_key =&gt; 'user_id'
  
    accepts_nested_attributes_for :update, :reject_if =&gt; lambda {|a| a[:body].blank?}
  
    ...
  end
  </code></pre>
  
  <p>Update model </p>
  
  <pre><code>class Update &lt; ActiveRecord::Base
     ...
    belongs_to :product, :foreign_key =&gt; 'product_id'
  
    geocoded_by :address
    reverse_geocoded_by :latitude, :longitude
  
    validates :body, :presence =&gt; true
  
  end
  </code></pre>