Ruby on Rails Mountable vs. Full Engine


A Rails Engine is basically a Rails application that you can attach to another Rails application to provide additional functionality. A Rails Engine is a Rails application in that it follows the same model view controller pattern as a “normal” Rails application.

What are some differences between working with an Engine vs. a “normal” Rails application? A Rails Engine is generated by the command: $ rails plugin new my_engine --mountable or $ rails plugin new my_engine --full. Because Engines are packaged as ruby gems, you must include your gem dependencies within the gemspec instead of the Gemfile. They will automatically be loaded in with the gemspec function in the Gemfile when you run bundler. You must also require the gems in the engine.rb file, or else you will likely see NoMethod errors. Also, a dummy application is generated within your test directory and is to be used for testing. You must copy over the engine migrations over into the dummy application, as well as any future applications you wish to use the Engine on. Fortunately, engines come with a rake command to do exactly that. rake my_engine:install:migrations

One of the first major differences between the two types is that the mountable engines have an “isolated namespace” while full engines do not. What this means is that the mountable engine is run in parallel with the host application while the full engine is integrated with the host application. Essentially, a full engine shares its models, views, controllers, helpers, and routes with the host application, while a mountable engine does not. The mountable engine comes with its own layout, javascript, and css files, while a full engine does not. A mountable engine requires you to “mount” the engine within your host application’s route file under a subdirectory path, while a full engine does not.

It seems as though a mountable engine would be ideal for a standalone application, for example, a blog or forum. It seems that a full engine would be ideal for augmenting an existing application, for example, an authentication solution or a pre-built administrative interface. Mountable engines appear to be good for working alongside an application. Full engines appear to be good for working with an application.