Railties - 何时使用
在阅读了一些关于 Railties 的文章后,我不明白我是否应该只为直接干扰 Rails 初始化的 gem/插件创建 Railsties(例如创建一个生成器,更改一些配置),或者我是否也应该将它用于仅向 Rails 添加功能的 gem/插件(例如,在 ActionView::Base 或 ActiveRecordBase 中包含某些模块)。
对此有什么想法或建议吗?
After reading some posts about the railties, I've didn't understand if i should only create railsties for gem/plugins that direct interfere with the rails initialization (e.g. create a generator, change some configuration) or if I should also use it for gem/plugins that only add functionality to rails (e.g. include some module in ActionView::Base or ActiveRecordBase).
Any idea or suggestion about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Railties 做到这两点甚至更多。 Railtie 可以实现一些钩子来创建生成器或在 Rails 启动时执行某些操作。人们还使用铁路运输来运输特定的宝石。它们并不真正“直接干扰”(正如您所说),它们将自己插入初始化链中。您可以在此处阅读有关 init 链的更多信息。第 2.10 项是调用自定义 Railties(即:您的代码)的地方(至少在启动时)。
You can do both and more with railties. There are hooks that a railtie can implement that would create a generator or do something on rails boot up. People also use railties to ship rails specific gems. They don't really "direct interfere" (as you said), they insert themselves in a initialization chain. You can read more about the init chain here. Item 2.10 is where the custom railties (ie: your code) gets invoked (at least for startup).