Re: Validating DateHelpers date_select

John Kopanas
Thu, 26 May 2005 13:06:13 -0000

Wow... thanks... makes sense.  But I am really new to both rails and
ruby and have a couple questions about your solution if you don''t mind.

Using the combination of what you wrote and:
http://wiki.rubyonrails.com/rails/show/HowToAddCustomValidationKeywords

I want to make a validate_older_then_18 so I can write in my model:

validate_older_then_18 :birthdate

Where would I extend the ActiveRecord::Base class?  What file do I
put this stuff in?

Thanks my friend.


On 26-May-05, at 8:20 AM, Dee Zsombor wrote:

> Just add a  validate member to the ActiveRecord::Base decendant class
> that has birthdate field. Inside chegk if they are 18 or above. If
> they are not add a desciptive message to the errors field. Something
> roughly looking like:
>
> def validate
>    if Time.now - birthdate < 18.years
>     errors.add("birthdate", "must be over 18")
>    end
> end
>
> Zsombor
>
> On 5/26/05, John Kopanas
<john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote:
>
>> I use date_select on my sign_up sheet for people to choose their
>> birthdate.  For people to join the website they have to be over 18.
>> How would I go about validating that in a rails way.  For all the
>> other validations I got them.  I just can''t figure out how to
do this
>> one yet.
>>
>> Any suggestions? :-)
>> _______________________________________________
>> Rails mailing list
>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>>
>
>
> --
> http://deezsombor.blogspot.com