2

I have model Customer payment as bellow ,

class Customerpayment < ActiveRecord::Base
#validation
  validates :amount ,   numericality: { greater_than_or_equal_to: 0 }
  validates :amount ,   presence: true
  validates :date   ,   presence: true


  validates_each :amount do |record, attr, value|
    record.errors.add(attr, I18n.t(:invalid_paid)) if !valid_paid_amount(record , value) 
  end
end

- the problem is the validation validates_each :amount works before validates :amount , presence: true and I want the last to work first , any help please to get validation validates :amount , presence: true work first

Ganesh Kunwar
  • 2,643
  • 2
  • 20
  • 36
AhmedShawky
  • 860
  • 2
  • 7
  • 18

1 Answers1

2

Rails does all the validations you specify, even if one fails. So, changing the order won't effect your code here.

Check out this answer for details

Community
  • 1
  • 1
CoolTapes
  • 417
  • 5
  • 14