What's New in Edge Rails: Pre-Environment Load Hook

Posted by ryan
at 3:13 PM on Sunday, November 18, 2007

For those looking for a way to manipulate your Rails application before the main initializer block of your environment.rb file runs, your wish has been answered.

If a config/preinitializer.rb file exists, Rails will load it prior to the environment.rb file, letting you have at the Rails classes before plugins do and before the environment is loaded.

tags: ruby, rubyonrails

Comments

Leave a response

  1. TedNovember 18, 2007 @ 04:07 PM

    Hmm, what about prepreinitializer.rb and postpreinitializer.rb? ;-)

  2. JoeNovember 18, 2007 @ 06:33 PM

    Is there a good use case for this?

  3. RSLNovember 19, 2007 @ 07:48 AM

    @ Joe: A good example for when I’ve had to use this functionality is ensuring a specific gem version [RedCloth] which Rails loads automatically itself. If you try to require it after the initializer block, it will fail silently and use whatever version of the gem Rails happened to load. In my specific case [which is admittedly edge] it wasn’t the version I desired.

  4. Rob SanheimNovember 19, 2007 @ 11:13 PM

    This will also make it much easier to test your Rails apps against multiple versions of Rails, which was a real pain point in getting 1.2.5 working with multi_rails. Version 0.3 (soon to be released) had to jump through many hoops to enable testing apps created with 1.2.5 against a rails 2.0 gem, so its good to see that pain going away.