Skip validation for some members in Devise model during password reset

前端 未结 4 1148
Happy的楠姐
Happy的楠姐 2021-01-18 12:09

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,

4条回答
  •  感情败类
    2021-01-18 12:31

    I had a similar problem because when my User is created not all its fields are required. The other fields' presence is checked on: :update using a validation.

    So this is how I solved:

    validates :birthdate, presence: true, on: :update, unless: Proc.new{|u| u.encrypted_password_changed? }
    

    The method encrypted_password_changed? is the one used in the Devise Recoverable.

提交回复
热议问题