This project is archived and is in readonly mode.

#5241 ✓invalid
mark

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

    mark July 30th, 2010 @ 07:12 PM

    If 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
    end
    

    end

    Ideas, anyone?

    Checked this vs ruby 1.9.2-head.

  • Jacek Becela

    Jacek Becela August 23rd, 2010 @ 04:48 PM

    Having the same problem on 1.8.7 and regular models located in app/models.

  • Jacek Becela

    Jacek Becela August 23rd, 2010 @ 04:52 PM

    Probably 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

    mark August 23rd, 2010 @ 05:33 PM

    Seems 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

    mark August 23rd, 2010 @ 05:35 PM

    isn't for long "hasn't been there for a long time" disambiguation fix

  • mark

    mark August 23rd, 2010 @ 05:36 PM

    isn't for long

    "hasn't been there for a long time" - disambiguation fix. Sry for flood, having no edit option hurts.

  • Rohit Arondekar

    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?

  • mark

    mark August 25th, 2010 @ 07:09 AM

    Yeah, seems it won't fix.

  • Rohit Arondekar

    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>

Pages