Re: Validating DateHelpers date_select

Dee Zsombor
Thu, 26 May 2005 12:20:55 -0000

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
>


--