Search code examples
ruby-on-railsvalidationdevise

Skip validation for some members in Devise model during password reset


My User (Devise) model also has name, city, nation, phone members.

In the create registration page - I validates_presence_of city, nation, phone, name, email, :on => :create

In the edit registration page - I validates_presence_of city, nation, phone, name, :on => :update

Now when I set a new password on forgot_password_page, it asks for the presence of city, nation, phone, name inside Devise::PasswordsController#update

How can I handle selective validations?

I am guessing it should be something like,

validates_presence_of city, nation, phone, name, :on => :update, :if => :not_recovering_password

def not_recovering_password
  # what goes here
end

Solution

  • Got an answer from José - https://github.com/plataformatec/devise/issues/1623