Rails caching my code after upgrading to Ruby 2.0 on Mac OS X Mountain Lion

612 views Asked by At

Rails 3.2.13 is caching my helper modules, controllers, and other ruby code in Development mode after upgrading to Ruby 2.0 from Ruby 1.8.7 on Mac OS X Mountain Lion 10.8.4

The code changes are only picked up after I restart the server every time even in the rails console. The reload! command in the console also does not work and does not reload my code changes until I restart the rails console again.

The Javascript and Sass files are not cached but the Views, Controller and other ruby code is. I checked the development.rb file and the following cache setting is set to false.

config.cache_classes = false

Also when starting the server it starts in development mode as seen on the console log

Rails 3.2.13 application starting in development on http://0.0.0.0:3000

Not sure what happened but I did change the timezone and time of my system for testing purposes and reverted the time back to the actual time.

I have even git cloned the repo again onto my system after restarting my machine with the correct time and timezone and still have the issue. Does anyone know how to fix this or how to force reload all the ruby code everytime the request is made in development mode?

1

There are 1 answers

2
Gary S. Weaver On

If you also upgraded recently from an older Rails version. If that is the case, note that lib is not autoloaded in Rails 3. You are talking about helper modules and controllers which should still be autoloaded, but lib won't be. You can change it to be autoloaded as noted in this answer, add another autoloaded dir, or move those classes until an existing autoloaded directory (e.g. app/models, if that is appropriate).

If you have stuff configured in config.autoload_once_paths then that could be a problem for reloading those, otherwise they should be reloaded per request per the guide (and you can look at the code here if you're curious about what is going on).

Also, check to make sure you are really running in development mode and note that you can't add lib to config.eager_load_paths in development.rb per this answer.

If you had time issues with the code, also maybe when you recloned the repo, you are still getting the wrong dates on the files. Try doing: find /path/to/rails/app -exec touch {} \; to update the file mod datetimes. (Also as an aside, you might want to be sure that the datetimes in your DB in created_at/updated_at are ok. Hopefully that isn't a problem, because that could be a mess.)

Finally, be sure that classes that are under the autoloaded directory correspond to the modules that they are in. For example Foo::BarsController could be in app\controllers\foo\bars_controller.rb but not in app\controllers\bars_controller.rb if you want it to be able to be autoloaded and reloaded properly.