开发者

ruby on rails redirecting to old param

开发者 https://www.devze.com 2023-03-02 03:51 出处:网络
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 redi

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_url take @user as an argument? How have you defined your route for that?

One thing I can think of immediately is @user.reload!.

0

精彩评论

暂无评论...
验证码 换一张
取 消