I have two classes with class variables. One of them derives from active
record, the other one does not. I initialize both members to NULL, then
lazy-instantiate them. The class which does not derive from active
record preserves the value correctly. The class which does derive from
active record always seems to be re-setting it to NULL.
class Class1 ## @@thelist holds the initialized value
@@thelist = nil
attr_accessor :name, :id
def self.retrieveall
if @@thelist.nil?
@@thelist = Array.new
entry = Locale.new
entry.id = "en"
entry.name = "english"
@@thelist << entry
//repeat to populate
end
@@thelist
end
end
class Class2 < ActiveRecord::Base
## anytime retrieveall is called @@thelist is always NULL. Why?
@@thelist = nil
attr_accessor :name, :id
def self.retrieveall
if @@thelist.nil?
@@thelist = Class2.all
end
@@thelist
end
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 16, 3:48 pm, Tomasz Romanowski <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have two classes with class variables. One of them derives from active > record, the other one does not. I initialize both members to NULL, then > lazy-instantiate them. The class which does not derive from active > record preserves the value correctly. The class which does derive from > active record always seems to be re-setting it to NULL. >Most classes in your app are reloaded between requests. Is this the problem ? Fred> class Class1 ## @@thelist holds the initialized value > > @@thelist = nil > attr_accessor :name, :id > > def self.retrieveall > if @@thelist.nil? > @@thelist = Array.new > > entry = Locale.new > entry.id = "en" > entry.name = "english" > @@thelist << entry > > //repeat to populate > end > > @@thelist > end > end > > class Class2 < ActiveRecord::Base > > ## anytime retrieveall is called @@thelist is always NULL. Why? > > @@thelist = nil > attr_accessor :name, :id > > def self.retrieveall > if @@thelist.nil? > @@thelist = Class2.all > end > > @@thelist > end > end > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 16, 4:23 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 16, 3:48 pm, Tomasz Romanowski <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > I have two classes with class variables. One of them derives from active > > record, the other one does not. I initialize both members to NULL, then > > lazy-instantiate them. The class which does not derive from active > > record preserves the value correctly. The class which does derive from > > active record always seems to be re-setting it to NULL. > > Most classes in your app are reloaded between requests. Is this the > problem ?To clarify, that of course only happens in development Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>> Most classes in your app are reloaded between requests. Is this the >> problem ? > > To clarify, that of course only happens in development >Yep, that''s it, thanks. Makes me wonder how I can control which classes should be reloaded. I''m trying to make something off of development.rb and production.rb. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Aug 16, 2010 at 7:10 PM, Tomasz Romanowski <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Yep, that''s it, thanks. Makes me wonder how I can control which classes > should be reloaded. I''m trying to make something off of development.rb > and production.rb.Rails comes with 3 development environments already ready to go, look database.yml. In development and testing, all classes are always reloaded. In production they are always cached. How is this not exactly what you want? :) -- Greg Donald destiney.com | gregdonald.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tomasz Romanowski
2010-Aug-17 23:33 UTC
Re: Re: activerecord re-sets class members to null??
> Rails comes with 3 development environments already ready to go, look > database.yml. In development and testing, all classes are always > reloaded.This does not seem to be true. In my example above, if a class does not derive from ActiveRecord::Base it preserves its class attributes between requests, a plausible explanation being that it''s NOT in fact reloaded.>In production they are always cached. How is this not > exactly what you want? :)Very simple. I only would like to be reloading the classes that I''m currently messing with. Reloading all the classes is a waste of time. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 18, 12:33 am, Tomasz Romanowski <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > Rails comes with 3 development environments already ready to go, look > > database.yml. In development and testing, all classes are always > > reloaded. > > This does not seem to be true. In my example above, if a class does not > derive from ActiveRecord::Base it preserves its class attributes between > requests, a plausible explanation being that it''s NOT in fact reloaded. >Deriving from activerecord or not should have no incidence. How the particular class is loaded can influence reloading, the only thing that you''re likely to do by accident is requiring a file explicitly Fred> >In production they are always cached. How is this not > > exactly what you want? :) > > Very simple. I only would like to be reloading the classes that I''m > currently messing with. Reloading all the classes is a waste of time. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.