提交 d34fd9fd 编写于 作者: C Caleb Wright

Update guides/source/active_record_validations_callbacks.md

In the expiration_date_cannot_be_in_the_past validation method, use `expiration_date.present?` instead of the double negative `!expiration_date.blank?`. Also join the comparisons with `&&` instead of `and`, which could cause unintended consequences.
上级 064ae350
......@@ -674,7 +674,7 @@ class Invoice < ActiveRecord::Base
:discount_cannot_be_greater_than_total_value
def expiration_date_cannot_be_in_the_past
if !expiration_date.blank? and expiration_date < Date.today
if expiration_date.present? && expiration_date < Date.today
errors.add(:expiration_date, "can't be in the past")
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册