有两个型号,
class Quote < ActiveRecord::Base
attr_accessible :quote_date
validates :quote_date, :presence => true
end
和
class Invoice < ActiveRecord::Base
attr_accessible :invoice_date
validates :invoice_date, :presence => true
validate :invoice_date_lesser
belongs_to :quote
private
def invoice_date_lesser
if invoive_date < quote_date
errors.add(:invoice_date, 'invoice date invalid')
end
end
end
如果我能获得一些关于如何通过客户端验证进行此验证和自定义验证的解决方案,那将有很大帮助