GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: This book is being merged into http://github.com/mattetti/merb-book/tree/master
Homepage: http://blog.new-bamboo.co.uk
Clone URL: git://github.com/deimos1986/book_mdar.git
Mentioned the need for validates_with_method to take a context as an 
argument
namelessjon (author)
Tue Jun 24 13:53:14 -0700 2008
commit  e2474d00fbe0f4ac93fe3f9a209175daf9e28d22
tree    f0feb0363a099efd6fc34ceddee0ad97e5548310
parent  79bd2094d6686f2a5b74cdb5aa4a50f599c899ac
...
340
341
342
343
 
344
345
346
...
362
363
364
365
 
 
366
367
368
...
340
341
342
 
343
344
345
346
...
362
363
364
 
365
366
367
368
369
0
@@ -340,7 +340,7 @@ difficult, and buy you the full power of dm-validations:
0
 
0
       validates_with_method :check_times
0
 
0
- def check_times
0
+ def check_times(context = :default)
0
         if start_time < end_time
0
           return true
0
         else
0
@@ -362,7 +362,8 @@ Of course, this custom validator can also be applied only in certain contexts,
0
 just by adding a `:when => [...]` on the `validates_with_method` line. This
0
 brings us a lot of flexibility, and as we're validating with a ruby method, we
0
 can get as complex as we need to specify our behaviour. Much nicer than just
0
-overriding valid.
0
+overriding valid. It's this functionality which requires the context to be
0
+passed in (Although your method can feel free to ignore it).
0
 
0
 #### Callbacks
0
 

Comments

    No one has commented yet.