I am having some problems with variable scoping.
I need to be able to set a variable that is accessable by other methods
within the class (or instance) (i.e not global).
An example is 2 pages that change a class variable:
class AjtestController < ApplicationController
def initialize @@variable = "init" end def show @display = @@variable @@variable = "change 1" end def list @display2 = @@variable @@variable = "change 2" end
When I view ‘show’ the page prints “init” (the page just prints
When I view ‘list’ the page prints “init” (the page just prints
This tells me that the class is being initialized (instantiated?) each
time I go to the ‘show’ or ‘view’ page.
If i remove the initialize method, i get an
“uninitialized class variable @@variable in AjtestController” error.
Is there something I am doing wrong here? I should be able to pass
variables between methods in the same class.