On Wed, Feb 4, 2015 at 12:12 AM, Andy Rose <[email protected]> wrote:
Hey guys, I posted this on Stackoverflow but it's not getting much love. > > Note in the question that I've found a solution to my problem. However I'm > curious as to what is going on here. Why does Rails encounter a race > condition when auto-loading an ActiveRecord model association...? > > > http://stackoverflow.com/questions/28267513/why-does-rails-throw-an-autoloading-constant-exception-when-i-use-threads > > Feel free to answer on SO if you have an account, but here's cool too. > Hey, I am not on SO. Constant autoloading is not thread-safe (it can't be). That's one of the reasons by default Rails eager loads the application code in production mode. There are a few things you can do. The easiest one is to enable eager loading by setting config.eager_load = true (in modern versions of Rails). Another possibility is to load the files with the involved classes using require_dependency in your script before spawning threads. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAM%3DYcdj%3D9MjQ1tx01OaSjYLo_ZWkRCrvG5sddcwjs9A3kWxVfA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

