我应该如何升级Rails应用程序以使用最新版本的Rails

时间:2022-10-06 14:09:00

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).

我正在研究目前使用Rails 1.2的Rails应用程序,所以我现在已经远远落后于最新的稳定版本(Rails 2.3)。

How should I go about the process of moving to a newer version of Rails?

我应该如何进入更新版本的Rails?

Should I upgrade one point release at a time or straight to Rails 2.3?

我应该一次升级一个版本还是直接升级到Rails 2.3?

How do I find out what has changed between versions of Rails, both

我如何找出Rails版本之间的变化

  • 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.
  • Rails更改需要我修改我的应用程序才能使用新版本。

(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.)

(我已经看到了关于升级机制的这个问题,但是我对我应该尽可能轻松地进行升级的过程更感兴趣。)

7 个解决方案

#1


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:

几个月前我经历了这个过程,进行了大量的研究并整理了一个rake任务(基于别人的脚本和额外的资源),可以帮助你标记要在代码中更改的内容。这是为了升级到Rails 2.2,所以它没有考虑到Rails 2.3的变化:

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.

哦,请务必检查您使用的插件和宝石是否兼容Rails 2.x并使用最新版本。

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.

我绝对同意一次性直接升级到Rails 2.3。并且不要继续推迟;没有升级就越久,越难以改变。并且维护Rails 1.x代码更难,因为支持它的资源更少。

#2


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.

在我工作的地方,去年夏天我们将一个非常大的应用程序从1.2升级到2.0.2,同时升级到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.

花了比预期更长的时间。该应用程序使用了一些被删除或弃用的旧功能(如ActionWebService),因此转换它们需要一些时间。但大多数情况下我们遇到了许多微妙的错误,例如单选按钮params如何工作的细微差别,其中一些可归因于Ruby(与Rails)升级。

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.

该应用程序的某些部分有不稳定的测试覆盖率。如果我们通过更好的测试进入它,那一切都会容易得多。

#3


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:

我刚刚开始将Rails 1.2.3应用程序升级到Rails 2.3.4环境。我遇到的基本步骤和警告是:

  • Create a skeleton application similar to your basic application
  • 创建类似于基本应用程序的框架应用程序

  • Check any environment.rb settings that you have in the old application to see whether these are required in the new version.
  • 检查旧应用程序中的任何environment.rb设置,以查看新版本中是否需要这些设置。

  • Migrate all the .rhtml files over to .html.erb; either using a script or manual. In my case there were 100+ files so automating it was way easier
  • 将所有.rhtml文件迁移到.html.erb;使用脚本或手册。在我的情况下,有100多个文件,所以自动化它更容易

  • Check any routes.rb changes that might need to be made given that RoR2.3.4 has simplified specifying the routes.
  • 检查可能需要进行的任何routes.rb更改,因为RoR2.3.4已经简化了指定路由。

  • Make sure you have a good SCM system at hand; eg either Git, SVN or even CVS so that small incremental changes can be captured.
  • 确保你手头有一个好的SCM系统;例如Git,SVN甚至CVS,以便捕获小的增量变化。

  • Check what plugins you need. In the beginning I simply removed all the plugins and in fact some were obsolete for the functionality that was to be implemented in the ported application.
  • 检查您需要的插件。在开始时,我只是删除了所有插件,实际上有些已经过时,因为要在移植的应用程序中实现这些功能。

  • Update any form_tag entries; for example <%= form_tag :action => 'search' %> becomes `<% form_tag :action => 'search' do %> otherwise you'll get some interesting error messages
  • 更新任何form_tag条目;例如<%= form_tag:action =>'search'%>变为`<%form_tag:action =>'search'do%>否则你会收到一些有趣的错误消息

  • Likewise change the <%= end_form_tag%> to closing the block as in `<% end %>
  • 同样,将<%= end_form_tag%>更改为关闭块,如同`<%end%>

  • Check if you have any plugins in the 1.2.3 version which are now removed from the core and have to be installed as plugins and configured for dependencies. I had some issues with the in_place_edit and calls made to the calendar popup.
  • 检查1.2.3版本中是否有任何插件,这些插件现在已从核心中删除,必须作为插件安装并配置为依赖项。我在使用in_place_edit和调用日历弹出窗口时遇到了一些问题。

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.

正如其他人所说,它可能需要比预期更长的时间。我已经做了大约30个小时的迁移工作。我估计它需要更长的时间;这很好;但是还有一些关于让PDF生成继续进行的工作。

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.

只是为了让应用程序在MS-Windows环境中运行更有趣; Ruby 1.8.7,Rails 1.2.3和MS SQL Server。目的是迁移到Linux环境; Ruby 1.9.x,Rails 2.3.4和MySQL数据库使得涉及MySQl服务器的数据库迁移工具。

#4


I think there are some Rails rake tasks out there you could get that will look for deprecations in your app.

我认为你可以获得一些Rails rake任务,可以在你的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.

此外,除了您在2.2和2.3中看到的发行说明页面之外,还应该在源本身中发布说明或更改日志。此外,您可以使用“rails x.x.x新功能”等搜索字词搜索博客帖子(使用谷歌博客搜索)。

#5


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.

我将首先回答我自己的问题,我已经设法通过我的谷歌搜索来找到资源。 Rails 2.2发行说明和Rails 2.3发行说明详细介绍了这两个版本中新增和更改的功能,但我找不到任何对早期版本如此明确的内容。

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.

我还没有发现升级时会发生什么破坏,除了这个发布公告,其中提到旧版本的Passenger不能与Rails 2.3一起使用。

#6


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:

我发现那些文档缺少一些细节,从2.1 => 2.2开始花了很长时间。这是我的笔记:

Biggest time sink: assert_redirected_to has changed significantly, no longer supporting hashes (at all?)

最大的时间汇:assert_redirected_to已经发生了重大变化,不再支持哈希(根本没有?)

Also, need to set environment/test.rb to disable forgery protection

此外,需要设置environment / test.rb以禁用伪造保护

If anyone's got news on these points for 2.3 that'd be super awesome.

如果有人在这些积分上得到2.3的消息那就太棒了。

#7


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:

在这一点上你可能已经有了很多这方面的经验,但是在搜索不同的Rails 1.2> 2.3升级问题的过程中遇到了这个问题,我想我自己会提出一些建议:

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.

我在一个相对简单的应用程序中遇到的最大突破是分页。我发现Classic Pagination插件对此非常天赐。

#1


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:

几个月前我经历了这个过程,进行了大量的研究并整理了一个rake任务(基于别人的脚本和额外的资源),可以帮助你标记要在代码中更改的内容。这是为了升级到Rails 2.2,所以它没有考虑到Rails 2.3的变化:

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.

哦,请务必检查您使用的插件和宝石是否兼容Rails 2.x并使用最新版本。

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.

我绝对同意一次性直接升级到Rails 2.3。并且不要继续推迟;没有升级就越久,越难以改变。并且维护Rails 1.x代码更难,因为支持它的资源更少。

#2


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.

在我工作的地方,去年夏天我们将一个非常大的应用程序从1.2升级到2.0.2,同时升级到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.

花了比预期更长的时间。该应用程序使用了一些被删除或弃用的旧功能(如ActionWebService),因此转换它们需要一些时间。但大多数情况下我们遇到了许多微妙的错误,例如单选按钮params如何工作的细微差别,其中一些可归因于Ruby(与Rails)升级。

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.

该应用程序的某些部分有不稳定的测试覆盖率。如果我们通过更好的测试进入它,那一切都会容易得多。

#3


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:

我刚刚开始将Rails 1.2.3应用程序升级到Rails 2.3.4环境。我遇到的基本步骤和警告是:

  • Create a skeleton application similar to your basic application
  • 创建类似于基本应用程序的框架应用程序

  • Check any environment.rb settings that you have in the old application to see whether these are required in the new version.
  • 检查旧应用程序中的任何environment.rb设置,以查看新版本中是否需要这些设置。

  • Migrate all the .rhtml files over to .html.erb; either using a script or manual. In my case there were 100+ files so automating it was way easier
  • 将所有.rhtml文件迁移到.html.erb;使用脚本或手册。在我的情况下,有100多个文件,所以自动化它更容易

  • Check any routes.rb changes that might need to be made given that RoR2.3.4 has simplified specifying the routes.
  • 检查可能需要进行的任何routes.rb更改,因为RoR2.3.4已经简化了指定路由。

  • Make sure you have a good SCM system at hand; eg either Git, SVN or even CVS so that small incremental changes can be captured.
  • 确保你手头有一个好的SCM系统;例如Git,SVN甚至CVS,以便捕获小的增量变化。

  • Check what plugins you need. In the beginning I simply removed all the plugins and in fact some were obsolete for the functionality that was to be implemented in the ported application.
  • 检查您需要的插件。在开始时,我只是删除了所有插件,实际上有些已经过时,因为要在移植的应用程序中实现这些功能。

  • Update any form_tag entries; for example <%= form_tag :action => 'search' %> becomes `<% form_tag :action => 'search' do %> otherwise you'll get some interesting error messages
  • 更新任何form_tag条目;例如<%= form_tag:action =>'search'%>变为`<%form_tag:action =>'search'do%>否则你会收到一些有趣的错误消息

  • Likewise change the <%= end_form_tag%> to closing the block as in `<% end %>
  • 同样,将<%= end_form_tag%>更改为关闭块,如同`<%end%>

  • Check if you have any plugins in the 1.2.3 version which are now removed from the core and have to be installed as plugins and configured for dependencies. I had some issues with the in_place_edit and calls made to the calendar popup.
  • 检查1.2.3版本中是否有任何插件,这些插件现在已从核心中删除,必须作为插件安装并配置为依赖项。我在使用in_place_edit和调用日历弹出窗口时遇到了一些问题。

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.

正如其他人所说,它可能需要比预期更长的时间。我已经做了大约30个小时的迁移工作。我估计它需要更长的时间;这很好;但是还有一些关于让PDF生成继续进行的工作。

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.

只是为了让应用程序在MS-Windows环境中运行更有趣; Ruby 1.8.7,Rails 1.2.3和MS SQL Server。目的是迁移到Linux环境; Ruby 1.9.x,Rails 2.3.4和MySQL数据库使得涉及MySQl服务器的数据库迁移工具。

#4


I think there are some Rails rake tasks out there you could get that will look for deprecations in your app.

我认为你可以获得一些Rails rake任务,可以在你的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.

此外,除了您在2.2和2.3中看到的发行说明页面之外,还应该在源本身中发布说明或更改日志。此外,您可以使用“rails x.x.x新功能”等搜索字词搜索博客帖子(使用谷歌博客搜索)。

#5


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.

我将首先回答我自己的问题,我已经设法通过我的谷歌搜索来找到资源。 Rails 2.2发行说明和Rails 2.3发行说明详细介绍了这两个版本中新增和更改的功能,但我找不到任何对早期版本如此明确的内容。

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.

我还没有发现升级时会发生什么破坏,除了这个发布公告,其中提到旧版本的Passenger不能与Rails 2.3一起使用。

#6


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:

我发现那些文档缺少一些细节,从2.1 => 2.2开始花了很长时间。这是我的笔记:

Biggest time sink: assert_redirected_to has changed significantly, no longer supporting hashes (at all?)

最大的时间汇:assert_redirected_to已经发生了重大变化,不再支持哈希(根本没有?)

Also, need to set environment/test.rb to disable forgery protection

此外,需要设置environment / test.rb以禁用伪造保护

If anyone's got news on these points for 2.3 that'd be super awesome.

如果有人在这些积分上得到2.3的消息那就太棒了。

#7


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:

在这一点上你可能已经有了很多这方面的经验,但是在搜索不同的Rails 1.2> 2.3升级问题的过程中遇到了这个问题,我想我自己会提出一些建议:

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.

我在一个相对简单的应用程序中遇到的最大突破是分页。我发现Classic Pagination插件对此非常天赐。