Devise 3 (rails 4) can't update user without password

前端 未结 7 1114
萌比男神i
萌比男神i 2021-02-06 00:34

I\'m trying to update a user without having to provide a password, but approaches that worked on older devise/rails versions no longer work with devise 3 and rails 4 strong para

7条回答
  •  被撕碎了的回忆
    2021-02-06 01:23

    The password validation is coming from the user model:

    validates :password, presence: true
    

    The solution is to only validate presence on create and allow_blank on update:

    validates :password, presence: true, length: {minimum: 5, maximum: 120}, on: :create
    validates :password, length: {minimum: 5, maximum: 120}, on: :update, allow_blank: true
    

提交回复
热议问题