-->

Upgrading from Rails 2.3.8 to 4.0

2019-01-10 10:11发布

问题:

I am running an application on Rails 2.3.8. I am planning to upgrade it to Rails 4.0 (which is in RC). What will be the easiest way for me to do this? Do I need to first upgrade to Rails 3.x?

Note: in my current implementation, I am using starling and ferret; as part of upgrade I am also considering to move to sidekiq and sunspot

回答1:

This is a multi-step process, and depending on the size of your application, it can take a long time. At each step, you'll want to test your application for bugs and problems and broken gems (because they are most certainly going to crop up). I have included links for the most complicated steps. Here is the path of least pain:

Update to Rails 2.3.18.

Update to Ruby 1.9.3.

Update to Rails 3.0.

  • Part 1
  • Part 2
  • Part 3

Update to Rails 3.1.

Update to Rails 3.2.latest.

Update to Ruby 2.0.latest.

Update to Rails 4.0.

Update from Rails 4.0 to Rails 4.1.

Update from Rails 4.1 to Rails 4.2.

Update from Rails 4.2 to Rails 5.0.

Update from Rails 5.0 to Rails 5.1.

Bonus: If you have a large application, this is going to take a long time. If you have a large team, long-running branches become a huge headache because of recurring merge conflicts. One strategy for mitigating this is to dual boot your application with both versions of Rails so that you can have the new version running on your master branch, rather than on a long-running branch of its own.



回答2:

Aaron Gray's answer is very useful, but sometimes it's very difficult after upgrading to find the differences between rails version in the code. I mean, many times after upgrading something doesn't work. Maybe could be some changes in the file or some file could be added or removed in newer version. There is a nice tool, how you can find out all differences between version and compare them. It's on Rails differences and could be very helpful to discover some potential mistakes and bugs.