How to update user info with restful_authentication plugin in Rails?

Posted by benoror on Stack Overflow See other posts from Stack Overflow or by benoror
Published on 2010-05-22T06:08:29Z Indexed on 2010/05/22 6:10 UTC
Read the original article Hit count: 266

Hi people,

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

I added this two methods to my controller:

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

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

      # Only update password when necessary
      params[:user].delete(:password) if pàrams[: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 }
        else
          format.html { render :action => "edit" }
          format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
        end
      end
    end

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, bute somehow when I click the save button it calls the create method, instead of update, using a POST http request. Any ideas?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-plugins