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])
end
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 }
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, 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?