Displaying 1 result from an estimated 1 matches for "statictest".
Did you mean:
staticlist
2007 Nov 28
6
Class variable does not retain its value in rails
...come my class variable ("static" in Java/C#)
doesn''t retain its value in Rails? The following code works well in the
Ruby console (the number is incremented all the time even though new
instances are created), but in Rails it always restarts at 1.
In the /libs/ folder:
class StaticTest
@@call_count = 0
def increment
@@call_count += 1
"@@call_count incremented to " + @@call_count.to_s
end
end
In the controller:
def index
@s = StaticTest.new
end
On the view:
<h1><%=@s.increment%></h1>
Could it be...