Category:Epsilon (game engine)
Category:Lua-scriptable game engines
Category:Video game development software
Category:Video game development software for LinuxQ:
Rails 3: Global variable scope
We have a rails app which currently has a global variable we would like to keep across multiple views. This particular variable is initialized in one controller and then passed to a method in a model. There are currently two potential ways to accomplish this:
1. Pass the variable as an argument to a method in a model.
model.method_name(:my_variable)
2. Define the variable in the controllers file and reference it from the views.
ViewHelper.my_variable
Is one approach preferred over the other? I'm leaning towards the first approach as it is more along the lines of what I think the convention should be.
A:
IMO, it's not recommended to use globals. This is definitely not encouraged in Ruby and Rails has pretty good conventions to follow.
However, it's completely fine to have variables scoped to a specific controller or model.
I prefer to put globals in config/initializers/ in the cases I need to access them from more than one controller/model and with or without a certain condition I'm using them.
It's a very fine practice to put them in a specific folder which makes it easier to make changes if needed.
Alzheimer’s Research at the University of Pennsylvania
Featured Author:
Daniel Brooks
Daniel Brooks is the University Professor and Edward Mallinckrodt Professor of Biochemistry and Molecular Biophysics at the University of Pennsylvania. He received his B.S. and Ph.D. from the University of Colorado. Dr. Brooks has conducted extensive research on the molecular structure and function of the catalytic subunit of cAMP-dependent protein kinase, known as protein kinase A, and on the structure of RNA polymerase II. His research interests include the regulation of gene expression and the control of cellular differentiation, specifically in the nervous system.
Webcasts
Whitepapers
Process automation has proven to be an important component in manufacturing. But, as manufacturing processes become more complex, manufacturers require new tools and technologies to help them work efficiently. Automation helps to standardize processes, improve quality control and increase throughput – all of which are important factors in 01e38acffe
Related links:
Comentários