简体   繁体   English

Rails 3:引擎和宝石有什么区别?

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

两者之间有什么区别,何时应该使用另一个而不是另一个?

An Engine in rails terminology is a actually a subapplication of a web-application. rails术语中的Engine实际上是Web应用程序的子应用程序。 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. 例如,博客,论坛或简单身份验证:这些不是完整的应用程序,而是可以添加到任何rails应用程序的页面/视图/控制器/模型。

In rails2 this would be done using a plugin . 在rails2中,这将使用plugin完成。 Now since rails3 an engine can be packaged in a gem . 现在因为rails3引擎可以包装在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. gem是一个ruby库,可以在http://rubygems.org上找到,它是将ruby代码打包并分发给其他rubyists的标准(唯一)方法。

So to conclude: 总结如下:

  • A gem: is a generic library, which can be easily installed, which are version-managed, have dependencies and such. gem:是一个通用库,可以轻松安装,由版本管理,具有依赖性等。
  • An engine: is a sub-application of a Rails application, and since Rails 3 these are distributed as a gem (which is awesome!). 引擎:是Rails应用程序的子应用程序,并且由于Rails 3,它们作为gem分发(这很棒!)。

So when will you use one or the other: 所以你什么时候使用其中一个:

  • create a gem if you want to share ruby-functionality 如果要共享ruby功能,请创建一个gem
  • create an engine (and package it in a gem) if you have parts of your rails application that can be used more generally. 如果您的rails应用程序的某些部分可以更普遍地使用,则创建一个引擎(并将其打包在gem中)。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM