[Ruby on Rails] Created update_without_password! Method in Devise that Raises Exception on Save Failure

Tadashi Shigeoka ·  Fri, June 1, 2012

In Ruby on Rails’ Devise, I created an update_without_password! method that raises an exception on save failure.

The update_without_password method defined in Devise returns true or false depending on the success or failure of the save operation.

I thought there might also be an exception-throwing update_without_password! method defined, but there wasn’t, so I created it.

class User < ActiveRecord::Base
  def update_without_password!(params, *options)

    if params[:password].blank?
      params.delete(:password)
      params.delete(:password_confirmation) if params[:password_confirmation].blank? 
    end

    clean_up_passwords
    update_attributes!(params, *options)
  end
end

That’s all.

・Reference: deviseで現在のパスワード無しでuserを更新する - komagata

That’s all from the Gemba.