Ruby on Rails 3 – Reload lib directory for each request

I couldn’t get any of the above to work for me so I dug in the Rails code a bit and came up with this: New file: config/initializers/reload_lib.rb if Rails.env == “development” lib_reloader = ActiveSupport::FileUpdateChecker.new(Dir[“lib/**/*”]) do Rails.application.reload_routes! # or do something better here end # For Rails 5.1+ ActiveSupport::Reloader.to_prepare do lib_reloader.execute_if_updated end # For Rails … Read more

Extending controllers of a Rails 3 Engine in the main app

By design, classes in a Rails::Engine are supposed to be scoped to the engine. That way they don’t introduce strange bugs by accidentally stomping all over code loaded in the main app or by other engines. Monkeypatching ActiveSupport::Dependencies to mix engines across-the-board is a really bad workaround. Just use a Rails::Railtie, instead. They have all … Read more

Rails Engine – Gems dependencies, how to load them into the application?

Include them in your gemfile and run bundle install. Then require them in your lib/<your_engine>/engine.rb file. Don’t forget to require rubygems require ‘rubygems’ require ‘paperclip’ require ‘jquery-rails’ require ‘rails3-jquery-autocomplete’ require ‘remotipart’ require ‘cancan’ Then in your host app (The app where you included your gem) run bundle install/ bundle update (bundle update did the trick … Read more

Rails 3.1: Engine vs. Mountable App

I have noticed the following: Full Engine With a full engine, the parent application inherits the routes from the engine. It is not necessary to specify anything in parent_app/config/routes.rb. Specifying the gem in Gemfile is enough for the parent app to inherit the models, routes etc. The engine routes are specified as: # my_engine/config/routes.rb Rails.application.routes.draw … Read more