Cookie 溢出 &关联错误

发布于 2024-12-21 17:45:49 字数 738 浏览 3 评论 0原文

我正在创建一个 Ruby on Rails 聊天室 Web 应用程序,但在尝试更新用户的“上次活动”时间时遇到了问题。每个“Client”模型都通过关联链接到“LoginStatus”模型。我每 5 秒轮询一次服务器并更新与客户端关联的模型的“latestNew”列。然而,专栏 1) 永远不会更新,2) 向我发送“Cookie 溢出”错误。这是我的代码。

jquery ajax 调用“updateLoginStatus”url

function updateLoginStatus () {
    $.ajax({
        url: "updateLoginStatus",
        type: "POST",
        success: function (data) {
            //Nothing to do on success for now
        }
    })
}

控制器

 def updateLoginStatus 
    currentUser = session[:user]
    newestTime = currentUser.login_status
    newestTime.latestTime = Time.now
    newestTime.save

    render :nothing => true
  end

每次我检查控制台时,latestNew 列仍未更新。我应该如何解决这个问题?

I'm creating a Ruby on Rails chatroom web application but ran into a problem while trying to update "last active" times for a user. Each "Client" model is linked to a "LoginStatus" model through an association. Every 5 seconds I poll the server and update the "latestNew" column for the model that is associated with the client. However, the column 1) never updates and 2) shoots me a "Cookie Overflow" error. Here is my code.

jquery ajax call to the "updateLoginStatus" url

function updateLoginStatus () {
    $.ajax({
        url: "updateLoginStatus",
        type: "POST",
        success: function (data) {
            //Nothing to do on success for now
        }
    })
}

The controller

 def updateLoginStatus 
    currentUser = session[:user]
    newestTime = currentUser.login_status
    newestTime.latestTime = Time.now
    newestTime.save

    render :nothing => true
  end

Every time I check the console the latestNew column is still not updated. How should I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪装你 2024-12-28 17:45:49

您正在从可能包含用户 ID 的用户检索会话。通过这个用户 ID,您应该访问用户模型并找到这个特定的用户。之后,您可以在该对象上调用login_status。这是您需要在控制器中使用的代码:

  currentUser = User.find(session[:user])

You are retrieving the session from the user which probably contains the user-id. With this user-id you should access the User model and find this particular user. After that you are able to call login_status on the object. This is the code what you'll need to use in the controller:

  currentUser = User.find(session[:user])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文