From f33f4b62656e9efd62071dc63cf375a31702477a Mon Sep 17 00:00:00 2001 From: Oriol Gual Date: Wed, 8 Jun 2011 02:53:47 -0700 Subject: [PATCH] Add ruby highlight --- Readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Readme.md b/Readme.md index 39ec3c5..dd7350c 100644 --- a/Readme.md +++ b/Readme.md @@ -3,31 +3,39 @@ A simple date validator for Rails 3. Compatible with Ruby 1.8.7, 1.9.2 and Rubinius 1.2.2. +```ruby $ gem sources -a http://gemcutter.org/ $ gem install date_validator +``` And I mean simple. In your model: +```ruby validates :expiration_date, :date => {:after => Proc.new { Time.now }, :before => Proc.new { Time.now + 1.year } } # Using Proc.new prevents production cache issues +``` If you want to check the date against another attribute, you can pass it a Symbol instead of a block: +```ruby # Ensure the expiration date is after the packaging date validates :expiration_date, :date => {:after => :packaging_date} +``` For now the available options you can use are `:after`, `:before`, `:after_or_equal_to` and `:before_or_equal_to`. If you want to specify a custom message, you can do so in the options hash: +```ruby validates :start_date, :date => {:after => Date.today, :message => 'must be after today'}, :on => :create +``` Pretty much self-explanatory! :)