Rails 3.2.x: how to reload application / classes during development?

I have a Rails code that doesn't fit neatly in a model or controller field. Since this answer , I created the app/classes directory. Rails 3 seems to automatically add this to the “boot path” in Rails, and my application correctly finds the classes that I define there, without using require statements.

However, the code in app/classes does not reload in development mode; if I made a change, I need to restart the server to see this change.

What is the correct way to make this directory "reloaded" in Rails 3.2.x? A few recommendations here recommend:

 config.autoload_paths += %W(#{config.root}/app/classes) 

but I believe that this simply leads to adding app/classes to the original set of directories to search for code in; doesn't seem to make them rebootable for every request (and, moreover, in 3.x it seems that app/* automatically added).

Update :

Figures, I came across a solution just 30 seconds after posting the question:

I had a class wrapped inside a module. As soon as I removed the surrounding "MyModule", it suddenly began to recharge. Based on the Java background and being burnt out of Ruby code that pollutes the global namespace, I developed the habit of putting everything into a module. I believe that the Rails “application” code should be outside of any module?

+7
source share
1 answer

Have you declared the module in a separate file or declared it implicitly inside the class? This may affect startup behavior. module Foo; class Bar module Foo; class Bar vs class Foo::Bar . Perhaps if the Rails autoloader cannot find foo.rb to go with the Foo module, it might skip the reboot.

+2
source

All Articles