@@ -4,26 +4,26 @@ 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
6
``` ruby
7
- $ gem sources - a http: / /gemcutter.org/
8
- $ gem install date_validator
7
+ $ gem sources - a http: / /gemcutter.org/
8
+ $ gem install date_validator
9
9
```
10
10
11
11
And I mean simple. In your model:
12
12
13
13
``` ruby
14
- validates :expiration_date ,
15
- :date => {:after => Proc .new { Time .now },
16
- :before => Proc .new { Time .now + 1 .year } }
17
- # Using Proc.new prevents production cache issues
14
+ validates :expiration_date ,
15
+ :date => {:after => Proc .new { Time .now },
16
+ :before => Proc .new { Time .now + 1 .year } }
17
+ # Using Proc.new prevents production cache issues
18
18
```
19
19
20
20
If you want to check the date against another attribute, you can pass it
21
21
a Symbol instead of a block:
22
22
23
23
``` ruby
24
- # Ensure the expiration date is after the packaging date
25
- validates :expiration_date ,
26
- :date => {:after => :packaging_date }
24
+ # Ensure the expiration date is after the packaging date
25
+ validates :expiration_date ,
26
+ :date => {:after => :packaging_date }
27
27
```
28
28
29
29
For now the available options you can use are ` :after ` , ` :before ` ,
@@ -32,9 +32,9 @@ For now the available options you can use are `:after`, `:before`,
32
32
If you want to specify a custom message, you can do so in the options hash:
33
33
34
34
``` ruby
35
- validates :start_date ,
36
- :date => {:after => Date .today, :message => ' must be after today' },
37
- :on => :create
35
+ validates :start_date ,
36
+ :date => {:after => Date .today, :message => ' must be after today' },
37
+ :on => :create
38
38
```
39
39
40
40
Pretty much self-explanatory! :)
0 commit comments