title: Validation before persistance on state_machine gem
body: <p>What is the correct syntax for performing a validation on before a transition in the <a href="https://github.com/pluginaweek/state_machine" rel="noreferrer">state_machine</a> gem?</p>
  
  <p>I've tried the following,</p>
  
  <pre><code>before_transition :apple =&gt; :orange do
    validate :validate_core
  end
  
  def validate_core
    if core.things.blank?
      errors.add(:core, 'must have one thing')
    end
  end
  </code></pre>
  
  <p>But I get the following error,</p>
  
  <pre><code>undefined method `validate' for #&lt;StateMachine::Machine:0x007ffed73e0bd8&gt;
  </code></pre>
  
  <p>I've also tried writing it as,</p>
  
  <pre><code>state :orange do
    validate :validate_core
  end
  </code></pre>
  
  <p>But this causes a rollback after the record is saved, which is less than ideal. I'd like to stop the state machine from transitioning into <code>:orange</code> in the first place.</p>
  
  <p>The core problem is that in my controller I have logic that relies on the result of <code>object.save</code>. The validation I have for my state machine doesn't kick in until after the initial save, so save gets returned as true and the controller goes on to logic it shouldn't hit if the object isn't valid.</p>
  
  <p>I've worked around this by testing the validity manually in addition to checking the save, but it feels like there should be a way to have the validation fire before the object saves. </p>