i think you should use the global var,start with “$”
the class-var is not persisstence between user-actions.
Never do that, because (among many other reasons) you should never
that the Ruby instance that serves one Action is the same as serves the
one. Your server could reboot, for example, between each time the user
at a View.
Wai T. wrote:
Thanks for the quick reply. I tried storing the information in the
model, but the information in the model cannot be retained. For
example, if I stored an global class variable @@ccount in Status, and
Status.gettext would increase the @ccount, when I output the value of
gettext in Status, it is always 1. It seems like the model is created
from scratch everytime the controller tried to call the methods inside.
What is ccount? The first step here is to give it a complete,
self-documenting name. Programs are hard enough to read without abusing
Do you really need a variable to count something, for the lifespan of
Rails website, such that each user sees a new value in it? If so, I
store it in a YAML file, and open it at a path like RAILS_ROOT +
‘/lib/my.yaml’. Then YAML::load it when you need it and YAML::dump it
If you don’t want to do that, note the only members of a Model that
a database are the attribute ones - not any extra variable you make, and
certainly not the class-instance @@ variables.
Make another Model and put only one record in it, with ccount in that
a better name). Then find(:first) this Model instance when you need the
record, and save it when it changes.
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!