问题描述
我正在使用它来访问模型中的会话.
I am using this to access session in Model.
http://www.zorched.net/2007/05/29/making-session-data-available-to-models-in-ruby-on-rails/
有人可以确认它也适用于 Apache + Passenger 部署吗?
Can anybody confirm that it will work with Apache + Passenger deployment too?
或者是否还有其他替代方法可以实现相同的目标?
Or if there are any other alternatives to achieve the same?
谢谢,
伊姆兰
推荐答案
是的.这是我发现在模型中使用会话数据的唯一有效方法.我也使用过它,并且从未遇到过 Apache + 乘客的任何部署问题.
Yes. It is the only efficient way I found to use session data in model. I also used it and never faced any deployment issue with Apache + passenger.
但是您需要确认何时使用会话值.在对服务器的每个新请求中,会话值都存储在线程中,我们可以在模型中访问它.如果您通过使用线程值应用任何逻辑,那么还要确保线程值也可能为零的情况.
But you need to confirm when you will be playing with session values. On each new request to server, session value gets stored in thread and we can access it in model. If you are applying any logic by using thread value, then also make sure with situation when thread value might be nil also.
因为我在开发中遇到了一个问题,我的每个代码都运行良好,但在生产中,在启动服务器期间它导致了一个问题,因为它最初认为线程值为 nil.
Because I got an issue where on development, my every code worked fine but on production, during starting server it caused an issue as initially it considered thread value as nil.
这篇关于确认 Apache 乘客部署:模型中的 rails 访问会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!