Hey all,
I have the following in my Controller:
class << self
attr_accessor :all_devices, :test
#def initialize(devices)
# @all_devices = devices
#end
end
def initialize_devices
AllDevicesController.all_devices = @devices_array
redirect_to :action => "show_all_devices"
end
Where devices_array is an array of devices.
def show_all_devices
@devices_array = AllDevicesController.all_devices
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @devices }
end
end
The problem here is when accessing @devices_array in the view
@devices_array is nil. I *know* the code is being executed in
initialize_devices because if I don''t redirect to show_all_devices I
can
manipulate the @devices_array within the initialize_devices view.
However, accessing AllDevicesController.all_devices in show_all_devices
results in nil.
Anyone know why?
--
Posted via http://www.ruby-forum.com/.
Tyler Knappe wrote:> Hey all, > > I have the following in my Controller: > > class << self > attr_accessor :all_devices, :test > #def initialize(devices) > # @all_devices = devices > #end > end > > def initialize_devices > AllDevicesController.all_devices = @devices_array > redirect_to :action => "show_all_devices" > end > > Where devices_array is an array of devices. > > def show_all_devices > @devices_array = AllDevicesController.all_devices > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @devices } > end > end > > The problem here is when accessing @devices_array in the view > @devices_array is nil. I *know* the code is being executed in > initialize_devices because if I don''t redirect to show_all_devices I can > manipulate the @devices_array within the initialize_devices view. > However, accessing AllDevicesController.all_devices in show_all_devices > results in nil. > > Anyone know why?Further @t = AllDevicesController.instance_variable_get(:@all_devices) Allows me to retrieve the all_devices var in initialize_devices but NOT in the show_all_devices portion of the controller. Instead, it is nil. -- Posted via http://www.ruby-forum.com/.
On Jul 22, 10:05 pm, Tyler Knappe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > The problem here is when accessing @devices_array in the view > @devices_array is nil. I *know* the code is being executed in > initialize_devices because if I don''t redirect to show_all_devices I can > manipulate the @devices_array within the initialize_devices view. > However, accessing AllDevicesController.all_devices in show_all_devices > results in nil. > > Anyone know why?because in development mode your source code is reloaded between requests (ie it is no longer the same AllDevicesController class). Fred> -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> On Jul 22, 10:05�pm, Tyler Knappe <rails-mailing-l...@andreas-s.net> > wrote: > >> >> The problem here is when accessing @devices_array in the view >> @devices_array is nil. �I *know* the code is being executed in >> initialize_devices because if I don''t redirect to show_all_devices I can >> manipulate the @devices_array within the initialize_devices view. >> However, accessing AllDevicesController.all_devices in show_all_devices >> results in nil. >> >> Anyone know why? > > because in development mode your source code is reloaded between > requests (ie it is no longer the same AllDevicesController class). > > FredThis was exactly the problem I was experiencing. Thanks Fred! -- Posted via http://www.ruby-forum.com/.