Updating `User` attributes without requiring password

前端 未结 9 1668
醉酒成梦
醉酒成梦 2021-01-30 17:27

Right now, users can edit some their attributes without having to enter their password because my validations are set up like this:

validates :password, :prese         


        
9条回答
  •  一个人的身影
    2021-01-30 18:22

    @user.username=params[:username]
    if @user.update_attribute(:email,params[:email])
    
      flash[:notice]="successful"
    else
      flash[:notice]="fail"
    end
    

    above code can update username and email field. because update_attribute can update dirty fields. but it is a pity, update_attribute would skip validation.

提交回复
热议问题