Take the 2-minute tour ×

I want to give the users the ability to change their account info with restful_authentication plugin in rails.

I added this two methods to my users controller:

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

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

      # Only update password when necessary
      params[:user].delete(:password) if params[:user][:password].blank?

      respond_to do |format|
        if @user.update_attributes(params[:user])
          flash[:notice] = 'User was successfully updated.'
          format.html { redirect_to(@user) }
          format.xml  { head :ok }
          format.html { render :action => "edit" }

Also, I copied new.html.erb to edit.html.erb. Considering that resources are already defined in routes.rb I was expecting it to work easily, but somehow when I click the save button it calls the create method, instead of update, using a POST HTTP request. Immediately after that it automatically logs out from the session.

Any ideas?

share|improve this question
Probably, if you showed your edit.html.erb, it would help to understand what is going on. –  Voyta May 22 '10 at 7:18
add comment

1 Answer

up vote 1 down vote accepted

Could it be possible that the selected user could not be found in your edit method? Then @user is empty and your form thinks that you are creating a new user.

Try to add debugging output in the edit method, like this:

def edit
  @user = User.find(params[:id])
  logger.debug "Found user = #{@user.inspect}"

And check if your log messages shows that the user is found or not.

share|improve this answer
add comment

Your Answer


