Rails 3: What is the difference between an Engine and a Gem?

前端 未结 1 1662

What is the difference between the two and when one should be used instead of the other?

1条回答
  •  不思量自难忘°
    2021-01-01 16:46

    An Engine in rails terminology is a actually a subapplication of a web-application. For instance, something like a blog, a forum, or simple authentication: these are not full-blown applications, but pages/views/controllers/models that can be added to any rails application.

    In rails2 this would be done using a plugin. Now since rails3 an engine can be packaged in a gem.

    A gem is a ruby library, which can be found on http://rubygems.org and it is the standard (only) way to package and distribute ruby code to other rubyists.

    So to conclude:

    • A gem: is a generic library, which can be easily installed, which are version-managed, have dependencies and such.
    • An engine: is a sub-application of a Rails application, and since Rails 3 these are distributed as a gem (which is awesome!).

    So when will you use one or the other:

    • create a gem if you want to share ruby-functionality
    • create an engine (and package it in a gem) if you have parts of your rails application that can be used more generally.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题