AhmedShawky
AhmedShawky

Reputation: 910

Rails validation precedence

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

Upvotes: 2

Views: 722

Answers (1)

CoolTapes
CoolTapes

Reputation: 417

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

Upvotes: 2

Related Questions