Skip to content

Commit f33f4b6

Browse files
committed
Add ruby highlight
1 parent 6ca2398 commit f33f4b6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,39 @@
33
A simple date validator for Rails 3. Compatible with Ruby 1.8.7, 1.9.2 and
44
Rubinius 1.2.2.
55

6+
```ruby
67
$ gem sources -a http://gemcutter.org/
78
$ gem install date_validator
9+
```
810

911
And I mean simple. In your model:
1012

13+
```ruby
1114
validates :expiration_date,
1215
:date => {:after => Proc.new { Time.now },
1316
:before => Proc.new { Time.now + 1.year } }
1417
# Using Proc.new prevents production cache issues
18+
```
1519

1620
If you want to check the date against another attribute, you can pass it
1721
a Symbol instead of a block:
1822

23+
```ruby
1924
# Ensure the expiration date is after the packaging date
2025
validates :expiration_date,
2126
:date => {:after => :packaging_date}
27+
```
2228

2329
For now the available options you can use are `:after`, `:before`,
2430
`:after_or_equal_to` and `:before_or_equal_to`.
2531

2632
If you want to specify a custom message, you can do so in the options hash:
2733

34+
```ruby
2835
validates :start_date,
2936
:date => {:after => Date.today, :message => 'must be after today'},
3037
:on => :create
38+
```
3139

3240
Pretty much self-explanatory! :)
3341

0 commit comments

Comments
 (0)