File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change 3
3
A simple date validator for Rails 3. Compatible with Ruby 1.8.7, 1.9.2 and
4
4
Rubinius 1.2.2.
5
5
6
+ ``` ruby
6
7
$ gem sources - a http: / /gemcutter.org/
7
8
$ gem install date_validator
9
+ ```
8
10
9
11
And I mean simple. In your model:
10
12
13
+ ``` ruby
11
14
validates :expiration_date ,
12
15
:date => {:after => Proc .new { Time .now },
13
16
:before => Proc .new { Time .now + 1 .year } }
14
17
# Using Proc.new prevents production cache issues
18
+ ```
15
19
16
20
If you want to check the date against another attribute, you can pass it
17
21
a Symbol instead of a block:
18
22
23
+ ``` ruby
19
24
# Ensure the expiration date is after the packaging date
20
25
validates :expiration_date ,
21
26
:date => {:after => :packaging_date }
27
+ ```
22
28
23
29
For now the available options you can use are ` :after ` , ` :before ` ,
24
30
` :after_or_equal_to ` and ` :before_or_equal_to ` .
25
31
26
32
If you want to specify a custom message, you can do so in the options hash:
27
33
34
+ ``` ruby
28
35
validates :start_date ,
29
36
:date => {:after => Date .today, :message => ' must be after today' },
30
37
:on => :create
38
+ ```
31
39
32
40
Pretty much self-explanatory! :)
33
41
You can’t perform that action at this time.
0 commit comments