gem 中同时支持 Rails 2 和 Rails 3
我想知道是否有任何 gem 同时支持 Rails 2 和 Rails 3?如果是这样,他们是如何做到的?代码中的简单条件?
这与我之前的问题有关: 打包 Rails 2.3 模型
我们的 Web 应用程序位于 Rails 2 上,但新的 API 应用程序将是 Rails 3两者之间已经存在一些小的不兼容性,可以通过发布脚本或运行时条件轻松修复。
[编辑] 我们确实计划最终让 API 服务器和应用程序服务器在 Rails 3 上运行,所以这只是暂时的。我目前的想法是 if-def 解决方案可能是最简单、最容易的。 (参见:http://www.infoq.com/presentations/Simple-Made-Easy )
I'm wondering if there are any gems out there that support both Rails 2 and Rails 3? If so, how do they do it? Simple conditionals in the code?
This is related to my previous question:
Packaging Rails 2.3 Models
Our webapp is on Rails 2, but the new API app is going to be Rails 3. There are already some minor incompatibilities between the two that would be easy to fix with a release script, or with runtime conditionals.
[edit]
We do plan to eventually have both the API server and App server running on Rails 3, so this would be for the interim. My current thinking is that an if-def solution might be the simplest and easiest. (See: http://www.infoq.com/presentations/Simple-Made-Easy)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 Rails 2 和 3 之间存在一些细微差别(例如重命名的方法),那么您应该使用一些条件。 的 示例
这是 Haml-rails If 你们之间存在重大差异,您应该保留两个单独的宝石。例如, will_paginate 对于 Rails 2 有 2.3 版本,对于 Rails 3 有 3.0 版本,因为 Active 中进行了重大重构记录3。仅第三版本正在开发中。
在这种情况下,如果您必须维护两个版本,您可能还需要考虑 3 个 gem:mygem(核心)、mygem-rails2、mygem-rails3。后两者将依赖于核心并重用相同的独立于 Rails 的代码。
If you have some minor differences between Rails 2 and 3 (e.g. a renamed method) you should go fine with a few conditionals. Here is an example from Haml-rails
If you have major differences you should keep two separate gems. For example, will_paginate has 2.3 version for Rails 2 and 3.0 one for Rails 3 because of a major refactoring in Active Record 3. Only 3rd version is under development.
In that case if you have to maintain two versions you may also want to consider 3 gems: mygem (core), mygem-rails2, mygem-rails3. The latter two will depend on the core and reuse the same rails-independent code.