Wincent Colaiuta
2008-Nov-19 10:47 UTC
Extending ActiveRecord::Base broken during 2.2.0 RC update
I''m trying to diagnose some breakage that occurred in the update from 2.1.2 to 2.2.0. The short version: an "acts_as_searchable" method added to ActiveRecord::Base doesn''t work anymore (raises NoMethodError). The long version: The method is added by a file inside the "lib" directory. The file is "required" from "config/environment.rb". If I print a debug messages from "config/environment.rb" I can see that the method was indeed added to ActiveRecord::Base; ie, the following prints "true": p ActiveRecord::Base.methods.include?(''acts_as_searchable'') If I print a debug message from inside a model file, the same statement prints "false". So somewhere between the evaluation of "config/environment.rb" and the evaluation of the model file which uses the "acts_as_searchable" method, the method is actually getting removed from ActiveRecord::Base. I am still digging around trying to find out why this is happening. Anyone have any suggestions or ideas? Cheers --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-19 10:57 UTC
Re: Extending ActiveRecord::Base broken during 2.2.0 RC update
On 19 Nov 2008, at 10:47, Wincent Colaiuta wrote:> > So somewhere between the evaluation of "config/environment.rb" and the > evaluation of the model file which uses the "acts_as_searchable" > method, the method is actually getting removed from > ActiveRecord::Base. > > I am still digging around trying to find out why this is happening. > Anyone have any suggestions or ideas?I suspect that the difference is that in production mode on 2.2 models are preloaded at the end of initialisation process, which is before the stuff at the end of environment.rb gets run, ie your models are loaded before you''ve required the file adding the stuff. Fred> > > Cheers > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wincent Colaiuta
2008-Nov-19 11:18 UTC
Re: Extending ActiveRecord::Base broken during 2.2.0 RC update
On 19 nov, 11:57, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 19 Nov 2008, at 10:47, Wincent Colaiuta wrote: > > > > > So somewhere between the evaluation of "config/environment.rb" and the > > evaluation of the model file which uses the "acts_as_searchable" > > method, the method is actually getting removed from > > ActiveRecord::Base. > > > I am still digging around trying to find out why this is happening. > > Anyone have any suggestions or ideas? > > I suspect that the difference is that in production mode on 2.2 models > are preloaded at the end of initialisation process, which is before > the stuff at the end of environment.rb gets run, ie your models are > loaded before you''ve required the file adding the stuff.Thanks, Fred. Makes sense, but it doesn''t explain the order in which I see the debug statements get logged... 0. "inside environment.rb" 1. "requiring lib file" 2. "ActiveRecord::Base now includes the desired method" 3. "evaluating model file" 4. "ActiveRecord::Base does not include the desired method" Must be some kind of anomaly caused by buffering or something which makes the statements get echoed out of order (I haven''t turned multi- threading on so I understand that this should all be happening in a single thread). This is actually in the test environment because I''m testing this by doing "rake spec". I tried "script/server" in the development environment and it works; tried it in production and I get the same failure. I then added the following to config/environments/test.rb and config/ environments/production.rb and those environments now work again. config.cache_classes = false So it works, but it seems like a bad idea to deploy with that configuration due to the performance hit of reloading the classes with every request. I suppose there must be a better solution. Any suggestions? Cheers, Wincent --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-19 14:42 UTC
Re: Extending ActiveRecord::Base broken during 2.2.0 RC update
On 19 Nov 2008, at 11:18, Wincent Colaiuta wrote:> > I then added the following to config/environments/test.rb and config/ > environments/production.rb and those environments now work again. >A better way could be to move the requires from your environment.rb into an initializer in config/initializers - this would mean they''re called at an appropriate moment in the boot process.> config.cache_classes = false > > So it works, but it seems like a bad idea to deploy with that > configuration due to the performance hit of reloading the classes with > every request. >Yeah that would be a super bad idea Fred> I suppose there must be a better solution. Any suggestions? > > Cheers, > Wincent >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---