重定向有一个有趣的问题。在我的用户更新页面(在 /username/edit),用户可以更新他们的姓名、电子邮件和用户名。更新完成后,如果用户更新他们的用户名,他们被重定向的路径(在这种情况下,它edit_user_path会导致错误:
Cannot redirect to nil!
我的用户控制器如下所示:
def update
    find_user
    if @user.update_attributes(params[:user])
        sign_in @user
        flash[:success] = "User updated"
        redirect_to edit_user_path
    else
        flash[:notice] = "There was an error updating this user:"
        redirect_to edit_user_path
    end
end
find_user是一种查找方法@user。
本质上,一旦发生此更新,我如何强制更新路由?