If you want to share this value between the methods of the same controller instance, declare the instance variable:
class BarsController < UsersController before_filter :init_foo_list def method1 render :method2 end def method2 @foo_list.each do | item| # do something end end def init_foo_list @foo_list ||= ['Money', 'Animals', 'Ummagumma'] end end
If you want to split this value on two controllers with a session, then:
class BarsController < UsersController before_filter :init_foo_list def method1 render :controller => "FoosController", :action => "method2" end def init_foo_list params[:shared_param__] ||= ['Money', 'Animals', 'Ummagumma'] end end class FoosController < UsersController def method2 params[:shared_param__].each do | item|
Give a unique name for the key for common parameters to avoid collision with existing keys.
Another option is to save the shared array in the session declaration, delete it until the final rendering.
Harish shetty
source share