title: Validate user's date of birth while registering, but not for Facebook and Google login in Ruby on Rails
body: <p>I want to check the condition for date of birth above 18.</p>
  
  <p>If I validate it then Facebook and Google logins are not working.</p>
  
  <p>If i leave the validation, then email registered users are able to register without entering date of birth. How can I do it ?</p>
  
  <p>My <strong>user.rb</strong>,</p>
  
  <pre><code>class User &lt; 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 =&gt; { :with =&gt; /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/, :message =&gt; "Password should contain at least 6 characters, one upper case, one lower case and one numeric." }, on: :create validates :password,  :format =&gt; { :with =&gt; /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/,       :message =&gt; "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 =&gt; lambda { 18.years.ago },
    #                           :before_message =&gt; "must be at least 18 years old"
  
    has_attached_file :avatar, :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100#" }
    validates_attachment_content_type :avatar, :content_type =&gt; /\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
  </code></pre>
  
  <p>If I delete the # before validates_date then Facebook and Google logins are not working. Is there another way to validate the date of birth for registering the user ?</p>