This project is archived and is in readonly mode.

autoload + config.threadsafe! broken?
Reported by mark | July 29th, 2010 @ 04:37 PM
How to reproduce:
0. Add lib/ to autoloaded paths
1. Have class Foo in lib/foo.rb
2. Have config.threadsafe! option on
3. Launch rails console production
4. Type Foo
Expected behaviour: autoloaded lib/foo.rb
Existing behaviour: missing constant exception
Quick note: for nested constants like Foo::Bar it does load foo/bar.rb file but not for ::Foo constant
Comments and changes to this ticket
- 
            
         mark July 30th, 2010 @ 07:12 PMIf anyone is interested, here's the solution (in initializer) I use for now: Dir.chdir "#{Rails.root}/lib/" do Dir["**/*.rb"].each do |lib| basename = lib.match(/(.*)\.rb$/)[1].classify parts = basename.split("::") if parts.size > 1 eval <<-EVAL module ::#{parts[0..-2].join("::")} autoload :#{parts[-1]}, "#{File.expand_path(lib)}" end EVAL else autoload parts[0].classify.to_sym, File.expand_path(lib) end endend Ideas, anyone? Checked this vs ruby 1.9.2-head. 
- 
            
         Jacek Becela August 23rd, 2010 @ 04:48 PMHaving the same problem on 1.8.7 and regular models located in app/models. 
- 
            
         Jacek Becela August 23rd, 2010 @ 04:52 PMProbably not a bug, following is the documentation for #threadsafe! # Enable threaded mode. Allows concurrent requests to controller actions and # multiple database connections. Also disables automatic dependency loading # after boot, and disables reloading code on every request, as these are # fundamentally incompatible with thread safety.
- 
            
         mark August 23rd, 2010 @ 05:33 PMSeems like that doc isn't for long. Probably the issue could be documented and closed. 
 The temporary solution I use still seems to work, though.
- 
            
         mark August 23rd, 2010 @ 05:35 PMisn't for long "hasn't been there for a long time" disambiguation fix 
- 
            
         mark August 23rd, 2010 @ 05:36 PMisn't for long "hasn't been there for a long time" - disambiguation fix. Sry for flood, having no edit option hurts. 
- 
         Rohit Arondekar August 25th, 2010 @ 03:03 AM- Importance changed from  to Low
 Mark, since documentation for #threadsafe! already mentions this, can this ticket be closed? 
- 
            
         
- 
         Rohit Arondekar August 25th, 2010 @ 11:31 AM- State changed from new to invalid
 
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
 Jacek Becela
      Jacek Becela
 Jeremy Kemper
      Jeremy Kemper
 mark
      mark
 Rohit Arondekar
      Rohit Arondekar