0

Possible Duplicate:
Where to put Global variables in Rails 3

Is it possible to set Site-Wide Global Variables in Ruby on Rails?

Community
  • 1
  • 1
Akhila M
  • 1
  • 1

2 Answers2

2

It is bad practice

$my_global_var = "I am very bad variable!"
fl00r
  • 82,987
  • 33
  • 217
  • 237
  • As far as I know, this is bad practice, **because it might not be thread safe**. I am not entirely sure of the details, but I do know that with several server-setups, the global variables will not only leak trough threads (`$user = current_active_user()` will give unexpected results, because $user is changed for all active threads). But might even leak trough to other apps, allthough I recall this only being a problem in mod_ruby. I have never investigated this deeply, hence my vagueness. I simply heeded the many warnings telling me "never ever to even consider it" :) – berkes Apr 04 '11 at 10:24
0

You can use general Ruby syntax $var_name, but I don't know any case when global variable is a best approach.

ceth
  • 44,198
  • 62
  • 180
  • 289