Hello everyone,
I'm almost cracking my head trying to do this birthdate validation. It turns out that I can only accept users with at least 18 years old and I'm trying to validate it writing this code on my user.rb fil at app/ models
class User < ActiveRecord::Base validates_presence_of :full_name validates_presence_of :street_address validates_presence_of :city validates_presence_of :state validates_presence_of :country validates_presence_of :zip_code validates_numericality_of :zip_code, :message => "must contain only numbers." validates_presence_of :phone validates_numericality_of :phone, :message => "must contain only numbers." validates_presence_of :email validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a- z]{2,})$/i validates_acceptance_of :policy_agreement, :message => "must be accepted. You have to read and agree with the Aykall Policies before signing in." validates_multiparameter_assignments :message => " is not a valid date." age_limit = Date.new(Date.today.year, Date.today.month, Date.today.day).change(:year => Date.today.year - 18) validates_numericality_of :birth_date, :less_than => age_limit, :message => "is invalid. You have to be at least 18 years old to sign in." end
I'm getting the error message "undefined method `change' for #<Date: 4908815/2,0,2299161>" but, honestly, I don't know what else to try.
Can anyone help me?
Thanks, Thiago Guerra