Rails plugins/engines: Loading files in development mode with "require_dependency"
Posted by Saulius Grigaitis 22/11/2007 at 22h36
The situation we discussed in pixel.lt blog post is interesting and some of you may have such situation. The guy introduced view of reusable components - rails engines. The main idea is to develop initial engine and then develop new engines, which extends the initial engine. Then develop more engines, which extends previous engines, then.... extend/change behavior of classes in main application. The issue is that files in plugins are not reloaded on each request in development mode, so the classes will be loaded only from main application after first request. To solve this problem just require the file paths of last engine in main application files with "require_dependency". So if you have model Car in engine A, then Car class is extended in engine B, and then class is extended in RAILS_ROOT/app/models, you need require path to Car file on engine B with "require_dependency" in the RAILS_ROOT/app/models/car.rb.

