Created
March 14, 2014 07:16
-
-
Save dtaniwaki/9543326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
flg = true | |
if de = options[:before] | |
de = Time.now if de == :now | |
flg &&= value <= de | |
end | |
if de = options[:after] | |
de = Time.now if de == :now | |
flg &&= de <= value | |
end | |
record.errors.add(attribute, options[:message] || :invalid) unless flg | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment