Skip to content

Instantly share code, notes, and snippets.

@jch
Created December 19, 2013 01:36
Show Gist options
  • Save jch/8032903 to your computer and use it in GitHub Desktop.
Save jch/8032903 to your computer and use it in GitHub Desktop.
Rails Engines

This is a quick brain dump of problems I've run into using Rails Engines.

Problems

  • Dependencies If an Engine requires a gem at version X, and the application requires the same gem at version Y. You could specify a lose version constraint on the Engine, but that's just asking for trouble. If the application updates to a newer version that the Engine isn't expecting, things go wrong.
  • Layouts/Assets To customize these, you need to overwrite certain magical paths. This ends up duplicating a lot of the engine and forces you to dig into the internals of how the Engine works rather than trusting it as a standalone component.
  • Models If you use an Engine's models, you're crossing into the Engine's abstractions again. It seems like a good place to share code, but it means your models will need to become versioned.
  • Complexity It's hard to debug problems when they come up. Is it coming from the engine, the app, or the app's overrides of the engine's defaults?
  • Extensibility It's hard to override behavior in an Engine. For example, if you wanted to share the same redis instance as your application, you could specify a configuration within the Engine, but these configurations add up over time, and end up tricky to maintain.

Alternative

I think most functionality an Engine provides can be provided directly as Rack middleware. Overall, I think Engines should not be a public feature of Rails. It makes a lot of sense for Rails internals to split things up with Engines, but they are too couple with Rails to be broadly useful as a standalone tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment