我应该如何升级 Rails 应用程序以使用最新版本的 Rails
我正在开发一个目前使用 Rails 1.2 的 Rails 应用程序,所以我现在距离最新的稳定版本(Rails 2.3)还有很长的路要走。
我应该如何进行迁移到新版本 Rails 的过程?
我应该一次升级一个版本还是直接升级到 Rails 2.3?
我如何找出 Rails 版本之间发生的变化,无论是
- 改进还是新功能,都让我有更多理由升级
- Rails 更改,这些更改将要求我修改我的应用程序,然后才能与新版本一起使用。
(我已经看到这个问题是关于升级机制的,但我更感兴趣的是我应该经历的使升级尽可能轻松的过程。)
I'm working on a Rails app that currently uses Rails 1.2, so I'm now quite a long way behind the latest stable release (Rails 2.3).
How should I go about the process of moving to a newer version of Rails?
Should I upgrade one point release at a time or straight to Rails 2.3?
How do I find out what has changed between versions of Rails, both
- improvements or new features that give me more reasons to upgrade
- Rails changes that will require me to modify my app before it will work with the new version.
(I have seen this question on the mechanics of upgrading, but I'm more interested in the process I should go through to make the upgrade as painless as possible.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
几个月前,我经历了这个过程,做了很多研究,并整理了一个 rake 任务(基于其他人的脚本加上额外的资源),这可能会帮助您标记代码中需要更改的内容。 这是为了升级到 Rails 2.2,因此不考虑 Rails 2.3 的更改:
http://gist.github .com/99535
哦,请务必检查您使用的插件和gems是否兼容Rails 2.x并使用最新版本。
而且我绝对同意一次性直接升级到 Rails 2.3。 不要总是拖延; 不升级的时间越长,就会变得越困难,因为会有更多的变化。 而且维护 Rails 1.x 代码更加困难,因为支持它的资源较少。
I went through this a few months back, did a lot of research and put together a rake task (based on someone else's script plus additional resources) that might help you in flagging things to change in your code. This was for upgrading to Rails 2.2 so it doesn't take into account Rails 2.3 changes:
http://gist.github.com/99535
Oh, be sure to check that the plugins and gems you use are Rails 2.x compatible and use the latest versions.
And I definitely agree with upgrading directly to Rails 2.3 in one go. And don't keep putting it off; the longer you go without upgrading, the more difficult it will be as more will have changed. And it's harder to maintaing Rails 1.x code as there are less resources that support it.
我的建议是花一周的时间偿还你积累的所有测试债务,然后一次性完成升级。
去年夏天,我工作的地方我们将一个非常大的应用程序从 1.2 升级到 2.0.2,同时升级到 Ruby 1.8.6。
花费的时间比预期要长得多。 该应用程序使用了一些已删除或弃用的旧功能(例如 ActionWebService),因此转换这些功能需要一些时间。 但大多数情况下,我们遇到了许多微妙的错误,例如单选按钮参数工作方式的细微差异,其中一些可归因于 Ruby(相对于 Rails)升级。
该应用程序的某些部分的测试覆盖率参差不齐。 如果我们进行更好的测试,一切都会容易得多。
My advice is to spend a week paying down any testing debt you've accumulated, and then do the upgrade all in one fell swoop.
Where I work we upgraded a very large app from 1.2 to 2.0.2 last summer, and at the same time upgraded to Ruby 1.8.6.
It took MUCH longer than expected. The app used a couple of old features that were removed or deprecated (like ActionWebService), so converting those took some time. But mostly we ran into a lot of subtle bugs, like slight differences in how radio button params work, some of which were attributable to the Ruby (vs. the Rails) upgrade.
Some parts of the app had spotty test coverage. If we had gone into it with better tests it all would have been much easier.
我刚刚开始将 Rails 1.2.3 应用程序升级到 Rails 2.3.4 环境。 我遇到的基本步骤和注意事项是:
environment.rb
设置,看看新版本中是否需要这些设置。routes.rb
更改,因为 RoR2.3.4 简化了指定路线。form_tag
条目; 例如<%= form_tag :action => 'search' %>
变为 `<% form_tag :action =>; “搜索”执行%> 否则你会得到一些有趣的错误消息<%= end_form_tag%>
更改为关闭块,如 `<% end %>;in_place_edit
和对calendar
弹出窗口的调用方面遇到了一些问题。正如其他人所说,这可能需要比预期更长的时间。 我已经完成了大约 30 个小时的迁移工作。 我原本预计需要更长的时间; 这样很好; 但在 PDF 生成方面仍有一些工作要做。
只是为了让它更有趣,该应用程序在 MS-Windows 环境上运行; Ruby 1.8.7、Rails 1.2.3 和 MS SQL Server。 目的是迁移到 Linux 环境; Ruby 1.9.x、Rails 2.3.4 和MySQL 数据库等涉及MySQl 服务器数据库迁移工具。
I've just started upgrading a Rails 1.2.3 application to a Rails 2.3.4 environment. The basic steps and caveats that I encountered are:
environment.rb
settings that you have in the old application to see whether these are required in the new version.routes.rb
changes that might need to be made given that RoR2.3.4 has simplified specifying the routes.form_tag
entries; for example<%= form_tag :action => 'search' %>
becomes `<% form_tag :action => 'search' do %> otherwise you'll get some interesting error messages<%= end_form_tag%>
to closing the block as in `<% end %>in_place_edit
and calls made to thecalendar
popup.As others have said it can take longer than expected. I've done about 30hrs work on the migration. I had estimated it to take a lot longer; so that was good; but still have some more work on getting PDF generation going.
Just to make it more interesting the application was running on a MS-Windows environment; Ruby 1.8.7, Rails 1.2.3 and MS SQL Server. The aim was to migrate to a Linux environment; Ruby 1.9.x, Rails 2.3.4 and MySQL database so that involved the MySQl server database migration tools.
我认为您可以获得一些 Rails rake 任务,这些任务将在您的应用程序中查找弃用内容。
只要您的应用程序处于版本控制中,我就会一次性进行升级,并一次查看一个错误消息。
另外,除了您看到的 2.2 和 2.2 版本的发行说明页面之外。 2.3、源代码本身应该有发行说明或更改日志。 另外,您可以使用“rails xxx 新功能”等搜索词来搜索博客文章(使用 google 博客搜索)。
I think there are some Rails rake tasks out there you could get that will look for deprecations in your app.
And as long as your app's in version control, I'd do the upgrade in one shot, and go through the error messages one at a time.
Also, aside from the release notes pages you saw for 2.2 & 2.3, there should be release notes or change logs in the source itself. Plus, you can search for blog posts (use google blog search) with search terms like "rails x.x.x new features", etc.
我将首先用我通过谷歌搜索找到的资源来回答我自己的问题。 Rails 2.2 发行说明 和 Rails 2.3 发行说明 提供了这两个版本中新功能和更改功能的详细信息,但我找不到对早期版本如此明确的内容。
除了 此发布公告其中提到旧版本的 Passenger 无法与 Rails 2.3 配合使用。
I shall start by answering my own question with the resources that I've managed to turn up with my Googling. The Rails 2.2 release note and Rails 2.3 release note give details of new and changed features in these two releases, but I can't find anything so definitive for earlier releases.
I also haven't found much about what will break when upgrading, apart from this release announcement which mentions that older versions of Passenger won't work with Rails 2.3.
我发现这些文档缺少一些细节并且从 2.1 => 2.2花了相当长的时间。 以下是我的笔记:
最大的时间消耗:
assert_redirected_to
发生了显着变化,不再支持哈希(根本不支持?)此外,需要设置
environment/test.rb
以禁用伪造保护如果有人如果能在 2.3 版中得到有关这些问题的消息,那就太棒了。
I found that those docs were missing a few details and moving from 2.1 => 2.2 took quite some time. Here are my notes:
Biggest time sink:
assert_redirected_to
has changed significantly, no longer supporting hashes (at all?)Also, need to set
environment/test.rb
to disable forgery protectionIf anyone's got news on these points for 2.3 that'd be super awesome.
此时您可能对此已经有丰富的经验,但我在搜索不同的 Rails 1.2>2.3 升级问题时遇到了这个问题,并认为我自己应该提出一些建议:
我在一个相对简单的应用程序是分页。 我发现经典分页插件对此来说是天赐之物。
You've probably had plenty of experience with this at this point, but I ran across this while searching for a different Rails 1.2>2.3 upgrade question, and thought I'd toss in a little advice myself:
The biggest break I had in a relatively simple app was with Pagination. I found the Classic Pagination plugin to be a godsend for this.