Is global variable in rails shared between different users?

拥有回忆 提交于 2019-12-24 22:22:05

问题


I have few variables which are used system-wide in my rails app. It runs well if I just have one user using the app. If there are more then one user, many unexpected problem pop out. I don't get any error log, and I have many unexpected behaviors. I believe most of those strange response are due to unexpected change of global variable.

I would like to know, is the value of global variable in Rails shared between different users?

thanks~


回答1:


This seems to be dependant upon your method of deployment.

It seems that mongrel and any fastcgi based deployment will each see different instances of the global variable whereas passenger will share it. This is based upon #821820 and many articles on rails and global variables including this one.

To re-iterate what Eimantas said above, globals are generally a bad idea and you should consider another alternative, perhaps storing them in the database or session.




回答2:


Global variables are a sign of [very/really] bad design. Have you considered SimpleConfig gem for this?



来源:https://stackoverflow.com/questions/2972524/is-global-variable-in-rails-shared-between-different-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!