I have an option for a user to update their username in their profile. However, when the url for their profile has been set as localhost/user/username and when they submit their changes, they are redirected to their old username (not the new updated one).
Here is my update from users_controller.rb
Any suggestions?
def update
@user = User.find_by_username(params[:id])
@page_title = "Edit Profile"
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(user_url,
:notice => "Your profile has been saved.") }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors,
:status => :unprocessable_entity }
end
end
end
also, I’m using
def to_param
username
end
Doesn’t
user_urltake@useras an argument? How have you defined your route for that?One thing I can think of immediately is
@user.reload!.