处理所有 Rails 请求共有的用户 ID 哈希值的最佳方式
每个客户端都由一个哈希值来标识,该哈希值随每个请求一起传递到服务器。 在这种情况下,处理跟踪用户会话的最佳方法是什么?
我对用户帐户等使用restful_authentication。预计很大一部分请求是在没有用户帐户的情况下发起的,而只是唯一的哈希值。
我对处理会话的方式的理解是有限的,所以请记住这一点。 :)
Each client is identified by a hash, passed along with every request to the server. What's the best way to handle tracking a users session in this case?
I'm using restful_authentication for user accounts etc. A large percentage of requests are expected to originate without a user account but just the unique hash.
My understanding of the way handles sessions is limited so please bear that in mind. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 URL 中使用此哈希意味着您没有 Rails 内置会话。 会话的目的是在请求之间提供某种状态感。 您已经提供了此状态,看到您正在传递此哈希,因此我认为您可以删除restful_authentication插件并执行类似以下操作:然后
,在控制器中执行
before_filter :require_login
需要登录才能访问。Using this hash in the URL means that you don't have Rails built-in session. The point of the session is to provide some sense of state between requests. You're already providing this state, seeing that you are passing this hash, so in my opinion you could remove the restful_authentication plugin and do something like this instead:
Then, do a
before_filter :require_login
in the controllers where login is required for access.取决于您想要执行的操作,但
session
哈希可能会提供您想要的内容。 会话将自身存储在某个地方(加密的 cookie、数据库或服务器上的文件),并在 cookie 中向客户端发送唯一标识符(类似于您的“哈希”)。 在后续请求中,将读取 cookie,并将相应用户的会话数据恢复到session
哈希中。Depends on what you're trying to do, but the
session
hash might provide what you want. The session stores itself somewhere (either an encrypted cookie, the database, or a file on the server), and sends a unique identifier to the client (similar to your "hash") in a cookie. On subsequent requests, the cookie is read and the corresponding user's session data is restored to thesession
hash.