Skip to content

Commit

Permalink
validate_timeliness not working.... made some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason1098 committed Feb 29, 2012
1 parent a111be7 commit a59bd9e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem 'rails', '3.2.1'
gem 'sqlite3'


gem 'validates_timeliness', '~> 3.0.2'
gem 'validates_timeliness'


# Gems used only for assets and not required
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sqlite3
uglifier (>= 1.0.3)
validates_timeliness (~> 3.0.2)
validates_timeliness
6 changes: 3 additions & 3 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Member < ActiveRecord::Base
has_many :membership

validates_presence_of :first_name, :last_name, :gender, :birthdate, :start_date
validates_date :birthdate, :on => :create
validates_date :start_date, :on => :create, on_or_after => '2011/01/01', on_or_after_message => 'start date must be after club inception!! DORK!'

# validates_date :birthdate, :on => :create, :before => lambda { 18.years.ago }, :before_message => 'must be 18 Years old to Join.'
# validates_date :start_date, :on => :create, on_or_after => '2011/01/01', on_or_after_message => 'start date must be after club inception!! DORK!'
#
end
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'rails/all'


if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
Expand Down
40 changes: 40 additions & 0 deletions config/initializers/validates_timeliness.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ValidatesTimeliness.setup do |config|
# Extend ORM/ODMs for full support (:active_record, :mongoid).
# config.extend_orms = [ :active_record ]
#
# Default timezone
# config.default_timezone = :utc
#
# Set the dummy date part for a time type values.
# config.dummy_date_for_time_type = [ 2000, 1, 1 ]
#
# Ignore errors when restriction options are evaluated
# config.ignore_restriction_errors = false
#
# Re-display invalid values in date/time selects
# config.enable_date_time_select_extension!
#
# Handle multiparameter date/time values strictly
# config.enable_multiparameter_extension!
#
# Shorthand date and time symbols for restrictions
# config.restriction_shorthand_symbols.update(
# :now => lambda { Time.current },
# :today => lambda { Date.current }
# )
#
# Use the plugin date/time parser which is stricter and extendable
# config.use_plugin_parser = false
#
# Add one or more formats making them valid. e.g. add_formats(:date, 'd(st|rd|th) of mmm, yyyy')
# config.parser.add_formats()
#
# Remove one or more formats making them invalid. e.g. remove_formats(:date, 'dd/mm/yyy')
# config.parser.remove_formats()
#
# Change the amiguous year threshold when parsing a 2 digit year
# config.parser.ambiguous_year_threshold = 30
#
# Treat ambiguous dates, such as 01/02/1950, as a Non-US date.
# config.parser.remove_us_formats
end
16 changes: 16 additions & 0 deletions config/locales/validates_timeliness.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
en:
errors:
messages:
invalid_date: "is not a valid date"
invalid_time: "is not a valid time"
invalid_datetime: "is not a valid datetime"
is_at: "must be at %{restriction}"
before: "must be before %{restriction}"
on_or_before: "must be on or before %{restriction}"
after: "must be after %{restriction}"
on_or_after: "must be on or after %{restriction}"
validates_timeliness:
error_value_formats:
date: '%Y-%m-%d'
time: '%H:%M:%S'
datetime: '%Y-%m-%d %H:%M:%S'

0 comments on commit a59bd9e

Please sign in to comment.