All, I upgraded to Rails 2.1 from 2.0.2 and my app. started to show problems with not having access to certain constants, etc. I have several "requires" set up in environment.rb so that various modules will be available for the app. I''ve played with it some, and the best theory that I can come up with so far is that the RAILS_ROOT/lib modules are now loaded before environment.rb is executed? Were there any major changes to boot.rb from 2.0.2 to 2.1? Confusing. Wes -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2008-Jun-12 17:40 UTC
Re: Did the order of autoloading assets change in Rails 2.1?
My problem appears to be that I have a library in RAILS_ROOT/lib (cache_manager.rb) that is _definitely_ being loaded _before_ config/environment.rb is being executed. Since the requisite requires to allow this library to load successfully are in environment.rb, and it hasn''t been executed yet, the file won''t load. So this leads me to two questions: 1) What causes the RAILS_ROOT/lib files to be loaded when you start up Rails? 2) Did this used to occur _after_ the execution of environment.rb but now it doesn''t? I recognize that there may be something in my app. that is causing the library to be loaded, but I haven''t found it yet, and of course, this only started happening when I moved to 2.1, so I''m thinking it''s a framework issue. Wes -- 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-/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-Jun-12 17:46 UTC
Re: Did the order of autoloading assets change in Rails 2.1?
On 12 Jun 2008, at 18:40, Wes Gamble wrote:> > My problem appears to be that I have a library in RAILS_ROOT/lib > (cache_manager.rb) that is _definitely_ being loaded _before_ > config/environment.rb is being executed. > > Since the requisite requires to allow this library to load > successfully > are in environment.rb, and it hasn''t been executed yet, the file won''t > load. > > So this leads me to two questions: > > 1) What causes the RAILS_ROOT/lib files to be loaded when you start up > Rails?I''d be surprised if anything in there is loaded systematically> > > 2) Did this used to occur _after_ the execution of environment.rb but > now it doesn''t? > > I recognize that there may be something in my app. that is causing the > library to be loaded, but I haven''t found it yet, and of course, this > only started happening when I moved to 2.1, so I''m thinking it''s a > framework issue.stick a breakpoint on the first line of cache_manager and see what the stack trace looks like ? Fred> > > Wes > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2008-Jun-12 17:55 UTC
Re: Did the order of autoloading assets change in Rails 2.1?
ANSWER: I had requires that were needed for libraries in RAILS_ROOT/lib at the bottom of my environment.rb file. When I moved these requires to _before_ the initializer block in environment.rb, everything worked fine. Wes -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2008-Jun-12 18:10 UTC
Re: Did the order of autoloading assets change in Rails 2.1?
THE REAL ANSWER: application.rb is now loaded as part of the call to the "Rails::Initializer.run" block in environment.rb, and it wasn''t in pre-2.1 versions of Rails. In this case, application.rb had dependencies that is was requiring. These libraries, which were require''d in application.rb in turn had dependencies that were not being "required in" until the end of environment.rb. Before this worked because environment.rb would be run before application.rb (the first time application.rb would be loaded was on the first request). But now, if application.rb needs anything to be loaded, you must either: 1) Ensure that the full dependency tree is satisfied in application.rb itself OR 2) Require in those lower level dependencies before the "Rails::Initializer.run" block in environment.rb. Wes -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Jon Garvin
2008-Jun-12 21:23 UTC
Re: Did the order of autoloading assets change in Rails 2.1?
Wes Gamble wrote:> THE REAL ANSWER: > > application.rb is now loaded as part of the call to the > "Rails::Initializer.run" block in environment.rb, and it wasn''t in > pre-2.1 versions of Rails. > > In this case, application.rb had dependencies that is was requiring. > > These libraries, which were require''d in application.rb in turn had > dependencies that were not being "required in" until the end of > environment.rb. > > Before this worked because environment.rb would be run before > application.rb (the first time application.rb would be loaded was on the > first request). > > But now, if application.rb needs anything to be loaded, you must either: > > 1) Ensure that the full dependency tree is satisfied in application.rb > itself > > OR > > 2) Require in those lower level dependencies before the > "Rails::Initializer.run" block in environment.rb. > > Wes > > > >THE FINAL ANSWER: ;-) 1) create an /initializers folder inside RAILS_ROOT/config 2) create a application.rb file inside that folder and move all your ''requires'' into it. If you create a new rails project under 2.1 and look at what it does in your environment.rb and in the initializers folder you''ll see the Rails 2.1 way this kind of this is supposed to be handled. My understanding is that you can create any/as many .rb files inside of initializers that you want (to separate different needs) and they''ll all be loaded. So, you could have an initializers/foo_feature.rb and an initializers/bar_extensions.rb, etc, etc, etc. -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2008-Jun-12 21:34 UTC
Re: Did the order of autoloading assets change in Rails 2.1?
Jon Garvin wrote:> THE FINAL ANSWER: ;-) > > 1) create an /initializers folder inside RAILS_ROOT/config > 2) create a application.rb file inside that folder and move all your > ''requires'' into it. > > If you create a new rails project under 2.1 and look at what it does in > your environment.rb and in the initializers folder you''ll see the Rails > 2.1 way this kind of this is supposed to be handled. > > My understanding is that you can create any/as many .rb files inside of > initializers that you want (to separate different needs) and they''ll > all be loaded. So, you could have an initializers/foo_feature.rb and an > initializers/bar_extensions.rb, etc, etc, etc.This is a good final answer. I already have 3 initializer files for various pieces of Rails that I''m monkey patching, and this makes sense as well. Too bad that this change in application.rb processing didn''t happen in 2.0 when I was having to hack all over my environment.rb file anyway :). WG -- 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-/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 -~----------~----~----~----~------~----~------~--~---