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 --------------------------------- Yahoo! FareChase - Search multiple travel sites in one click. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 11/19/05, rohit mehra <rohitm2010-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> 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 > > ------------------------------ > Yahoo! FareChase - Search multiple travel sites in one click.<http://us.lrd.yahoo.com/_ylc=X3oDMTFqODRtdXQ4BF9TAzMyOTc1MDIEX3MDOTY2ODgxNjkEcG9zAzEEc2VjA21haWwtZm9vdGVyBHNsawNmYw--/SIG=110oav78o/**http%3a//farechase.yahoo.com/> > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Nov 19, 2005, at 2:33 PM, Peter Michaux wrote:> 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 11/19/05, rohit mehra <rohitm2010-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> 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 Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org 509-577-7732 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails