title: Rails: How to use before_save to change a field value based on another field?
body: <p>I'm trying to set a boolean field to false based on the value of another boolean field.  I tried the following with an ActiveRecord model:</p>
  
  <pre><code>  before_save :reconcile_xvent
  
    def reconcile_xvent
      self.xvent_hood = false if !self.xvent_plenum?
    end
  </code></pre>
  
  <p>But this doesn't work.  Now, many of my unit tests fail with:</p>
  
  <pre><code>ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved
  </code></pre>
  
  <p>How can I set xvent_hood to be false if xvent_plenum is false?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Here's what works (some of which comes from the comments/answers below):</p>
  
  <pre><code>before_validation :reconcile_xvent
  
  def reconcile_xvent
    if self.xvent_hood?
      self.xvent_hood = false unless xvent_plenum?
    end
  end
  </code></pre>
  
  <p>I couldn't figure out to make it work without the "if self.xvent_hood?" part....</p>