Chapter 17. Engines


This chapter covers

  • The importance of engines for Rails 3
  • Building a new engine and exploring the base
  • Using behavior-driven development to develop an engine
  • Releasing the engine as a gem
  • Integrating an engine with an app

Engines are a new feature for Rails 3.[1] They are effectively miniature applications that provide additional functionality to an application, and they function in much the same way as an application.

1 Although in previous versions they were supported by a plugin written by the community:

Back in chapter 6, you used the Devise gem, which itself is an engine. Other engines include the RailsAdmin[2] and forem[3] engines.

An engine allows you to share common functionality across applications in the form of a gem or a plugin.[4] This functionality could be an authentication system such as Devise, a commenting engine, or even a forum engine. If there’s ever been a need to have the same features across an application, this is what engines were made for.

4 In Rails 3, these two are basically interchangeable. One lives in vendor/plugins, the other is installed using gem. For all intents and purposes, they work in a near-identical manner. Developers should try to use gems where possible, as they are versioned and easy to upgrade to specific versions, where plugins are not.

17.1. A brief history of engines

17.2. Why engines are useful

17.3. Brand-new engine

17.4. Setting up a testing environment

17.5. Writing your first engine feature

17.6. Adding more posts to topics

17.7. Classes outside your control

17.8. Releasing as a gem

17.9. Integrating with an application

17.10. Summary