Instance / class variable?

hi all
i want a variable to be accessed from more than one method of a
controller, (value same) & from .rhtml
if i use a global var, application goes berserk, puttting one user’s
data to another
i know its some basic i missing ,
but plz help, clear it
thanks
bye

I’m no expert but it looks like each action method of a controller is an
instance method. So I think you want an instance variable (@var) which
will
automatically be available in the .rthml file. If it doesn’t work you
could
post here your trimmed down controller and view code.

Peter

On Nov 19, 2005, at 2:33 PM, Peter M. wrote:

hi all
i want a variable to be accessed from more than one method of a
controller, (value same) & from .rhtml
if i use a global var, application goes berserk, puttting one
user’s data to another
i know its some basic i missing ,
but plz help, clear it
thanks
bye

rohit-

Put this in the top of your controller where you want to have a

shared var. I will assume the var is @foo

MyController < ApplicationController

before_filter :setup_foo
attr_reader :foo

def setup_foo
@foo = “Whatever you want @foo to contain”
end

end

Now @foo will be available to every action method in your controller

and also in your views for that controller. If you want @foo to be
available in all your controllers and view, put that code in your
application.rb ApplicationController.

HTH-

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732