Upgrading Rails app from 3.2.6 to 3.2.18 - ruby-on-rails

I have a Rails app that was built on 3.2.6. I want to upgrade it to the latest version of 3.2 (which seems to be 3.2.18). Can anyone tell me what changes will need to be made besides just changing the Rails version number in the Gemfile? Is there a more stable version I should be upgrading to instead of 3.2.18? I am extremely new to Rails development and I am not finding much help elsewhere on the web.
EDIT: I tried updating to 3.2.18 briefly just to see if the behavior of my application changed, and once I had done so, the main page would not even load, claiming the template was missing. This seems to indicate that I need to manually go in and fix something.

Rails uses semantic versioning. This means that 3.2.x will work if the application was working in any version of 3.2.x.
The latest stable version of Rails is 4.1. I would recommend building new applications with the latest version, unless you know for certain a required feature was deprecated.
EDIT: This response on rails core describes the versioning https://github.com/rails/rails/issues/9979
X.Y.Z
Z - only bug fixes, no API changes.
Y - new features, may contains API changes.
X - new features, will contains API changes. Just bumped in special occasions

change the rails version in Gemfile and run 'bundle update rails'

Related

upgrade ruby on rails application

Currently my application run on rails 3.1.3 & ruby 1.9.3.
I want to upgrade my application into rails 4.1 & ruby 2.1
Can anyone tell me how to upgrade the rails application ?
Thanks in advance
There is no specific defined way to upgrade. You can take reference from http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html or many other blog posts that people have written based on their personal experience. Just google them.
http://www.sitepoint.com/get-your-app-ready-for-rails-4/
https://developer.uservoice.com/blog/2012/03/04/how-to-upgrade-a-rails-2-3-app-to-ruby-1-9-3/
However follow a few points to make it easier. Upgrade one at a time. Better upgrade your ruby first, then rails in second cycle.
Do through testing at each step as the gems are likely to fail due to their dependencies.
Upgrade you gems manually and avoid bundle update
As addition to #shivam 's answer.
Guides often do not contain all the info. And they often do not say why some steps a necessary.
The most professional way is to read the release notes at least for the next major version.
Rails follows semantic versioning, meaning that all following 4.x.x versions are not allowed to introduce breaking public api changes.
Check the Rails 4 Release Notes. Watch out for things marked as deprecated and stuff that was extracted to a separate gem. The best tutorial available is the Upgrading to Rails 4 Screencast.
The most tricky part about the upgrade is the change from protected_attributes in models to strong_parameters in the controllers as a default mechanism against mass assignment protection.
If your app already heavily relies on protected_attributes it can be a tremendious task to move this protection outside of the model to every controller. In that case it is recommended to stick with protected_attributes by just including them as extra gem(same name).
In case of the ruby update. You can almost safely update to 2.1.2 from 1.9.3. Ruby follows semver only since Major version 2. If there even have been some incompatibilities since 1.9.3 the probability is very little, that your app used this features. We could upgrade all of our apps from 1.9.x to the last 2.x.x without a single ruby code change

Upgrading from Rails 2.3 to Rails 4.0

We have an application which is currently on Rails version 2.3.12 and Ruby version 1.8.7. We want to update our application to Rails 4.0 and Ruby 2.1.0. We have around 200 models and 150 controllers.
I would like to know how big an effort is it to undergo the upgrade process. Also can you provide steps which can be followed for the upgrade. Should we first upgrade Ruby and then Rails or vice-versa?
What you want to achieve is gonna be an epic effort. I can't provide you the step by step instructions because it's impossible to cover all the cases in a single answer.
I recommend to not upgrade Ruby and Rails in parallels, but in small steps.
The complexity of the upgrade itself is huge, but it's not impossible as long as you have a reasonable test coverage of you application. I really hope you have tests. If you don't, then you can't even think to start an upgrade like this and you first need to ensure a minimum coverage for the product.
My suggestion is to follow this roadmap
Upgrade Ruby from 1.8.7 to 1.9.3. Rails 2.3 is supposed to be compatible with Ruby 1.9 and you'll get the benefit of a more recent Ruby version. In fact, several gems have dropped support for Ruby 1.8.
Leave the app settle and run for a while, just to make sure you can find and fix incompatibilities. Every time you find an issue, reproduce it with a test, then fix it.
Upgrade Rails from 2.3 to 3.0.
Same as point 2.
Upgrade Rails from 3.0 to the latest 3.x version.
Same as point 2.
Upgrade Ruby from 1.9.3 to 2.0. The upgrade should be trivial.
Same as point 2.
Upgrade Rails from 3.x to the latest version
A few notes
The reason I suggested you to not upgrade from Rails 2.3 directly to 4, it's because it's almost impossible.
The reason I suggested you to not upgrade form Rails 2.3 directly to the latest 3.x, it's because from 3.0 to 3.x there is the asset pipeline new feature that is gonna cause you several headaches. It's better to handle this step separately and not in a big upgrade.
Ruby 1.9 handles encoding differently than Ruby 1.8. Rails 2.3 is not well prepared for this.
The issues often lead to hard errors, and may occur at unexpected places (like when you want to show a error message)
A good (or scary) overview is on this blog entry:
http://www.rvdh.de/2010/01/06/why-you-cant-run-rails-23-apps-on-ruby-19/
I also lost a lot of time trying to bring Rails 2.3.x to work with Ruby 1.9.x
(Maybe it is possible if you are always use plain ascii)
So you need first update to Rails 3.0 and then to Ruby 1.9.3 (or both at the same time)
The asset pipeline is nice when it works, but upgrading is difficult enough.
So I would just disable it until you are on Rails 4.0.
There is a lot changed with the views, like form_for helper.
It is good when you have tests that render each view at least once. You then will get deprecation warning for things that have changed.
If this is not realistic, then you should try to test all things of your app manually, and
grep the log files for the deprecation warnings.
Many deprecations in Rails 3.0 will lead to errors or wrong behaviour in Rails 3.1.
For updating the ruby and rails version to new is not take much more time but in your code you have to change all the quires and model scopes and whatever which does't work in new rails version of deprecated in new ruby and rails versions.And one more thing may be many gems which have support to ruby 1.8.7 will not support the new ruby version and same thing for the rail.
My suggestions is just, you first check the dependencies of your application with new versions and the get a decisions.I have knowledge about it because i have also upgrade a full application from ruby 1.8.7, rails 2.3.5 to ruby 1.9.3 and rails 3.2.13.

Upgrading from Rails 2.3.8 to 4.0

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

Upgrading Rails Versions

I know that to update Rails, you update the version number in your Gemfile and then bundle update but what I am getting confused about is how do you know if anything else has changed?
How do I know if there are config options to add or anything else anywhere. Contents of files or whole directories.
Any clues?
Rails upgrades fall into the following categories;
Patch version upgrades (e.g., 3.2.10 to 3.2.11)
Minor version upgrades (e.g., 3.1.X to 3.2.X)
Major version upgrades (e.g., 3.X.X to 4.X.X)
Major/Minor Upgrades
Major and minor version upgrades require a lot of work, and I'd urge you to look out for screencasts from people like Peepcode or Peter Cook.
Sometimes its easier to do a rails new and copy all the initializers and config files over the top of your app, and do a diff to find what's changed.
I'd always suggest doing a minor version at a time.
For example, if you are still on 2.3.x, you should first upgrade to 3.0.x, then the 3.1.x, then to 3.2.x
Patch Upgrades
Patch version upgrades are generally simpler (and important since they often include security fixes). Look out for any deprecation notices in your logs, and fix the changes.
Do a Gemfile update, run your tests, and most of the time it'll be fine.
It certainly depends on which versions you're upgrading between. In general, Rails does a pretty good job documenting what you'd need to change in the release notes, for example: http://edgeguides.rubyonrails.org/3_2_release_notes.html
Sometimes, deprecation notices will help you after you upgrade. Alternatively, you can rails new a brand new app, and compare configuration files of the clean-slate app with your existing one.
The Railsdiff.org site can provide the difference between the contents of a vanilla Rails project (ie as if running Rails New) between any two versions of Rails going back to 3.0.0. I find this particularly useful to determine if there have been any changes to the standard configuration options between versions or if there are new files added/removed from a standard project which you may want to copy over to your existing project.
This won't provide any insight into what has changed in the framework itself, for that you'll need to jump into the change logs for each release. Easiest way to pick them up is check out the Ruby on Rails blog which includes notes and links for each released version.

Would there be compatibility issues upgrading rails 2 to rails 3?

Im considering upgrading a rails 2 app to rails 3 for a number of reasons (rails 3 features, certain plugins require rails 3 etc.)
Obviously ill have to update/grade some of the plugins as well. But concerning the code itself, should there be any compatibility issues when upgrading to 3? I know rails 3 changes a lot of helpers and syntax to make things easier, but do the older and more complicated ways still work (ex. gems in envioronment.rb, not Gemfile).
Also, anyone know a good tutorial on how to do it?
I have written a blogpost about it, where I point to the standard resources, but also handle some more deeper problems I encountered.
Hope this helps.
You may try this plugin to check your application compatibility in Rails 3. https://github.com/rails/rails_upgrade
If you want to upgrade from Rails 2 to Rails 3, first make sure to upgrade to the latest 2.3 version.
Then, before migrating, there is a list of changes you can make to make your Rails 2.3 application behaving like a Rails 3 application. Once you applied these changes, chances are the number of issues will be smaller and you can upgrade to Rails 3.
Once you installed Rails 3, use the rails_upgrade plugin to check the incompatibilities and fix them.

Resources