I have a template that I use for creating Rails web sites. There is
some limited template configuration data which I store in a global
hash variable. This hash variable is initialized in the applications
controller. It all works just fine. However, I think that I need to
clean up my act a bit. The applications controller is probably not
the best place to initialize the global variable. I tried to do it
with an assignment statement in an initializer file; but, it didn't
work (i.e., view templates didn't see it for some reason). Can
someone please tell me why that is and what might work? Also, I fully
recognize that global variables are to be avoided (but it sure works
fine ). Does anyone have a suggestion as to what I might use to
replace the global variable?
Interesting. The procedure that you describe is much different than
what I expected. So, I guess that I'm not surprised that what I did
failed to work. Thanks. I'll give it a try.
This appears to be a rather basic issue that, for whatever reason,
doesn't seem to get much attention.
I've reviewed everything. My conclusion is that, for my purposes, the
very basic first approach of just declaring the single needed global
constant in a file added to the initializers directory is enough to
meet my needs.
This appears to be a rather basic issue that, for whatever reason,
doesn't seem to get much attention.
I've reviewed everything. My conclusion is that, for my purposes, the
very basic first approach of just declaring the single needed global
constant in a file added to the initializers directory is enough to
meet my needs.
I hope you don't mean "global" as in "Ruby global with a dollar sign".
If so, that's asking for trouble. Please see Railscast #85 for a simple
way of doing this right.