Ruby On Rails 3 中 railties 和引擎之间的差异 [英] Differences between railties and engines in Ruby On Rails 3
问题描述
我阅读了一些关于这些论点的文件,但我并不清楚它们是什么,它们之间有什么区别,以及它们中的一个是否符合我的需要.
I read a few documents on these arguments, but I did not understand clearly what they are, what are the differences between them and if one of them fits my needs.
我需要编写一个可以插入其他应用程序的应用程序,我想将它作为 gem 包含在其他应用程序中.基本上我需要几个模型,一个控制器,没有视图,加上一些初始化,支持来自托管应用程序和生成器的配置参数.
I need to write a piece of application which can be plugged in other application and I want to include it in other applications as a gem. Essentially I need a couple of models, one controller and no views, plus some initialization, support for configuration parameters coming from the hosting app and a generator.
我走对了吗?
我应该阅读什么来了解如何做到这一点?
What should I read to understand how to do that?
更新:
可以在此处找到一篇非常好的文章,其中包含大量 af 详细信息.
A very nice article with a lot af details can be found here.
本质上:
Railtie 是 Rails 框架的核心,提供了几个钩子来扩展 Rails 和/或修改初始化过程.
Railtie is the core of the Rails Framework and provides several hooks to extend Rails and/or modify the initialization process.
Rails::Engine 只不过是一个已经设置了一些初始化程序的 Railtie.由于 Rails::Application 和 Rails::Plugin 是引擎,这里描述的相同配置可以用于所有三个.
A Rails::Engine is nothing more than a Railtie with some initializers already set. And since Rails::Application and Rails::Plugin are engines, the same configuration described here can be used in all three.
推荐答案
Railtie 可能可以完成您所描述的操作,但使用引擎可能更理想.引擎可以有自己的配置,也可以像 Rails 应用程序一样工作,因为它允许您以与常规 Rails 应用程序相同的方式将/app 目录包含控制器、视图和模型.
Railtie can probably do what you describe, but it may be more desirable to use an engine. The engine can have its own configuration and also acts like a Rails application, since it allows you to include the /app directory with controllers, views and models in the same manner as a regular Rails app.
这篇关于Ruby On Rails 3 中 railties 和引擎之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!