Displaying 1 result from an estimated 1 matches for "validate_start_date_before_end_date".
2006 Jul 17
1
How to DRY up validates_presence_of
Given the case of validating the presence of an attribute and then
performing other tests on said attribute, how do you go about not having
to check for nil in the other tests?
Example:
validates_presence_of :start_date, :end_date
validate :validate_start_date_before_end_date
def validate_start_date_before_end_date
# without this check an exception will be thrown on access to the
nil attribute
return if start_date.nil? || end_date.nil?
if end_date < start_date
errors.add_to_base ''End date cannot be earlier than start date.''...