title: Validation before saving Rails
body: <p>I would like to carry out a validation before saving by determining if a User has filled in a particular field, the Payment amount field below and chosen status = "Closed" before submitting the form. If he does one without the other then the form should not save</p>
  
  <p>Edit page</p>
  
  <pre><code>&lt;%= simple_form_for @invoice, :html =&gt; { :class =&gt; 'form-horizontal' } do |f| %&gt;
  &lt;%= render "shared/error_messages", :target =&gt; @invoice %&gt;
  
  &lt;%= f.association :customer, disabled: @invoice.persisted? %&gt;
  &lt;%= f.input :due_date, as: :string, input_html: { class: "datepicker" }, disabled:  @invoice.persisted? %&gt;
  &lt;%= f.input :invoice_date, as: :string, input_html: { class: "datepicker" }, disabled: @invoice.persisted? %&gt;
  &lt;%= f.input :payment_method, as: :select, :collection =&gt; [['Cash','Cash'],['Cheque','Cheque'],['In-House transfer','In-House transfer'],['Account Ledger','Account ledger']], :selected =&gt; ['Cash','Cash'] %&gt;
  &lt;%= f.input :reference_no, :label =&gt; 'Payment Reference No', as: :string %&gt;
  &lt;%= f.input :amount, as: :string %&gt;
  &lt;%= f.input :payment_date, as: :string, input_html: {class: "datepicker"} %&gt;
  &lt;%= f.input :status, as: :select, collection: Invoice::VALID_STATUS %&gt;
  </code></pre>
  
  <p>VALID_STATUS = [ 'Draft', 'Open', 'Closed', 'Void' ] in Invoice.rb</p>
  
  <p>I would like that if the user changes the Status to Closed he should have entered an amount in the form. A user should not be able to change status to closed without entering an amount</p>