Skip to content

Instantly share code, notes, and snippets.

@dtaniwaki
Created March 14, 2014 07:16
Show Gist options
  • Save dtaniwaki/9543326 to your computer and use it in GitHub Desktop.
Save dtaniwaki/9543326 to your computer and use it in GitHub Desktop.
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