开发者

Rails: is it a good idea to store the view in a global var?

I'm thinking of storing the view, what i mean by view is 开发者_如何学运维like this: app/views/profiles/index.html.haml into this i would do $view = self

then in other parts of my app i would use and edit the $view var.

it might get troubles?


Some people consider defining global variables in ruby as something very wrong. I concur. Encapsulation is very important.

Think about this for a second - when you start a rails server, global objects are stored in memory for as long as the server is running whereas when you request a php file they last only for the duration of that one request. So this means that in rails, global variables will be shared among all the users. This goes for class variables as well.

So you may never have problems in development, but when you have more than one user at the same time you could be in for some unwanted sideeffects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜