Ruby on Rails 中的 Gem 与插件与引擎 [英] Gem Vs Plugin Vs Engine in Ruby on Rails

查看:25
本文介绍了Ruby on Rails 中的 Gem 与插件与引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby on Rails 中的 Gem 包、插件和引擎有什么区别?

我认为我们在 Rails3.2 之前使用插件,在 Rails3.2 发布之后我们使用 gem 包作为插件,但是我们如何在 ROR 中使用引擎?

解决方案

您从 Rails 2 中了解到的插件(即 vendor/plugins 文件夹下的插件)在 Rails 3.2 中被弃用;Rails 4 中完全删除了对它的支持.现在,有一个 "gemified plugin"<的概念/a> 插件本质上是作为 gem 构建的,可以在不同的 Rails 应用程序之间共享.

但是要回答关于 gems 与插件的问题,请查看此 Stackoverflow 答案.长话短说,Rails 2 Universe 中的plugins 是 Rails 应用程序的扩展,而 gem 是打包的 ruby​​ 应用程序.>

至于 Rails 引擎,我发现这是 Rails 引擎的一个非常简单直观的定义:

<块引用>

Rails Engines 基本上是一个完整的 Rails 应用程序,它位于另一个应用程序的容器中.换句话说,正如文档所指出的:应用程序本身基本上只是根级别的引擎.多年来,我们已经将 sen 引擎视为诸如 devise 或 rails_admin 之类的 gem 的一部分.这些示例通过提供大量安装"到应用中的相对独立的功能来展示引擎的强大功能.

而且由于 rails 引擎和插件都是 ruby​​ 应用程序的类型,所以从技术上讲,它们都可以打包并用作 gem(通常).

What is difference between Gem package, plugin and Engine in Ruby on Rails ?

I think we use plugin before Rails3.2 and after rails3.2 is release we are using gem package as plugin but how can we use engine in ROR ?

解决方案

Plugins as you knew them from Rails 2 (i.e. plugins under the vendor/plugins folder) were deprecated for Rails 3.2; support for it was completely removed in Rails 4. Now, there's a concept of a "gemified plugin" where the plugins are essentially built as gems, and can be shared across different Rails applications.

But to answer your question about gems vs plugins, check out this Stackoverflow answer. Long story short, plugins from the Rails 2 universe is an extension of the rails application, whereas a gem is a packaged ruby application.

As for Rails engines, I've found this to be a pretty easy and intuitive definition of a Rails engine:

Rails Engines is basically a whole Rails app that lives in the container of another one. Put another way, as the docs note: an app itself is basically just an engine at the root level. Over the years, we’ve seen sen engines as parts of gems such as devise or rails_admin. These example show the power of engines by providing a large set of relatively self-contained functionality "mounted" into an app.

And since both rails engines and plugins are types of ruby applications, they can all technically be packaged and used as a gem (usually).

这篇关于Ruby on Rails 中的 Gem 与插件与引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆