Rails验证优先级

时间:2013-10-24 11:17:17

标签: ruby-on-rails

我的模型客户付款方式如下,

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

- 问题是验证validates_each :amountvalidates :amount , presence: true之前有效,我想让最后一个先工作,任何帮助请让validation validates :amount , presence: true先工作

1 个答案:

答案 0 :(得分:1)

Rails执行您指定的所有验证,即使失败也是如此。因此,更改订单不会影响您的代码。

查看this answer了解详情