Skip to content

Instantly share code, notes, and snippets.

@adamcrown
Created May 8, 2012 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcrown/2640427 to your computer and use it in GitHub Desktop.
Save adamcrown/2640427 to your computer and use it in GitHub Desktop.
Rails validator for time strings
class TimeStringValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
require 'chronic'
record.errors[attribute] << "doesn't seem to be a valid time" unless Chronic.parse(value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment