Skip to content

Commit

Permalink
Add ruby highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual committed Jun 8, 2011
1 parent 6ca2398 commit f33f4b6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Readme.md
Expand Up @@ -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! :)

Expand Down

0 comments on commit f33f4b6

Please sign in to comment.