I want to check the condition for date of birth above 18. (If i validate it then fb and google logins are not working) (If i leave the validation, then email registered users can able to register without entering date of birth). How can i do it ? My user.rb,
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:google_oauth2, :facebook]
validates :fullname, presence: true, length: {maximum: 40}
validates :password, :format => { :with => /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/,
:message => "Password should contain at least 6 characters, one upper case, one lower case and one numeric." }, on: :create
validates :password, :format => { :with => /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/,
:message => "Password should contain at least 6 characters, one upper case, one lower case and one numeric." }, on: :update, allow_blank: true
#validates_date :date_of_birth, :before => lambda { 18.years.ago },
# :before_message => "must be at least 18 years old"
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#" }
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.fullname = auth.info.name
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.image = auth.info.image
user.password = Devise.friendly_token[0,20]
end
end
end
If i delete the # before validates_date then fb and google logins are not working. Is there anyother way to validate the date of birth for registering the user ?
Aucun commentaire:
Enregistrer un commentaire