Rails 3:引擎和 Gem 有什么区别? [英] Rails 3: What is the difference between an Engine and a Gem?
问题描述
这两者有什么区别,什么时候应该用一个而不是另一个?
What is the difference between the two and when one should be used instead of the other?
推荐答案
Rails 术语中的 Engine
实际上是 Web 应用程序的子应用程序.例如,博客、论坛或简单的身份验证之类的东西:这些不是成熟的应用程序,而是可以添加到任何 Rails 应用程序的页面/视图/控制器/模型.
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.
在 rails2 中,这将使用 plugin
来完成.现在,从 rails3 开始,引擎可以打包在 gem
中.
In rails2 this would be done using a plugin
. Now since rails3 an engine can be packaged in a gem
.
gem
是一个 ruby 库,可以在 http://rubygems.org上找到a> 并且这是将 ruby 代码打包并分发给其他 ruby 人员的标准(唯一)方式.
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:是一个通用库,可以轻松安装,受版本管理,具有依赖项等.
- 引擎:是 Rails 应用程序的子应用程序,从 Rails 3 开始,这些引擎作为 gem 分发(这太棒了!).
那么你什么时候会使用其中一个:
So when will you use one or the other:
- 如果您想分享 ruby 功能,请创建一个 gem
- 如果您的 Rails 应用程序的某些部分可以更广泛地使用,请创建一个引擎(并将其打包到 gem 中).
希望这会有所帮助.
这篇关于Rails 3:引擎和 Gem 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!