require current_password to update user information

Rails newbie here, I have been stuck on this for two days and can’t figure out why its not working.

I want users to confirm/verify themselves by entering their current/old password before any information is updated.

This is what My user_controller update action looks like

I’m currently using rails 3.2 with the basic has_secured_password authentication that comes with it.

def update

@user = User.find(params[:id])

respond_to do |format|

if @user.update_attributes(params[:user])

format.html { redirect_to users_url, notice: “User #{} was successfully updated.” }

format.json { head :no_content }


format.html { render action: “edit” }

format.json { render json: @user.errors, status: :unprocessable_entity }




here’s my form view

<% if params[:action] == “edit” %>

<%= f.label :password %>

<%= f.password_field :current_password, :placeholder => “current password” %>

<% end %>

<%= f.label :password, “Password” %>

<%= f.password_field :password, size: 40 %>

<%= f.label :password_confirmation, ‘Confirm’ %>

<%= f.password_field :password_confirmation, size: 40 %>

I’ve tried using a before_update :confirm_password in the User model, but it hasn’t worked.

I created a private method in the user controller


def password_match

@user = User.find(params[:id])



then call a before_filter :password_match, :only => [:update] in the user controller.

Can anyone help, please. Thank you.

How is your user model look like ?