Upgrading Rails Versions - ruby-on-rails

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.

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 Rails app from 3.2.6 to 3.2.18

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'

Rails 3 is out, but will they still support Rails 2.3.x?

Rails 3 is out and every one is excited (etc etc).
However, I'm not ready to update to it yet for a couple reasons:
Not all gems I use are supported.
Just finally got my head around 2.3.x.
My client expects software that is reliable.
So, right now I'm running 2.3.5 and will be upgrading to 2.3.8 soon. But what about any security patches or parallel feature updates that 3 might get? Will there be a 2.3.9? Will there be a 2.4? Does anyone know?
Looking on https://rails.lighthouseapp.com/projects/8994-ruby-on-rails there is a 2.3.10 milestone, so they will at least have that.
You can see from the commit log that there are still commits to the 2.3 branch eventhough it's not as active as the 3.x branch. 37signals are still using 2.3 on many of their apps that's why you will see many patches/commits coming from Jeremy, one of 37signals employee. I don't think they will make any major changes that will break your apps though.
Judging by the lastest commit to 2.3.9pre ("preparing for 2.3.9") and the open tickets (none), it looks like Rails 2.3.9 will be released any day now.
Actually upgrade to 3.0 doesn't break that much. There's few gotchas, but they are mostly very well documented. Most common gems are already compatibile with rails 3 (at least the newest beta versions). I am sure, that by the time you would finish upgrading all of those would have stable relases.
I would go rather for 3.0 instead of going for an upgrade in 2.3.x branch.
It is very crucial to have lots of well placed tests for your application. This way you can easily see if anything breaks.
I found much many problems after switching to Ruby 1.9.x, then after going from Rails 2.3.x to Rails 3. Actually now I am using REE 1.8.7 with Rails3.

How hard is it to upgrade from Rails 1.2.3 to 2.3.5?

Is it even worth it?
I'm working on assessing a legacy code base for a client -- the source code has been largely untouched since 2007 and it's built with Rails 1.2.3.
My Rails experience began at version 2.1 -- the code is fairly stock/scaffold like and devoid of meaningful tests -- I was curious to even see if I could get it running locally -- but, I'm not even sure where to start. Right off it doesn't even know what 'rake db:create' means. Ha!
Is it going be a major pain to even getting it running in 2.3.5? Should I bother?
Would love to hear your thoughts.
Thanks
If you're going to be actively developing the site, then yes, it is worth sinking the time into the project to bring it up to date. A lot has happened since Rails 1.2 which will make development a much more pleasant experience. Life without named scopes or RESTful resources is really difficult. If you're just patching the odd thing here and there, it may be worth leaving it mostly as-is and just dealing with the eccentricities.
Since 1.2.3 is just prior to the releases building up to 2.0 where a lot of warnings and deprecation notices were introduced, you could have quite a chore.
Some things to keep an eye out for:
Migrations are now date-tagged, not numbered, but are at least backwards compatible
Many vendor/plugins may not work, have no 2.x compatible version, or need to be upgraded
The routing engine has changed, and the name of many routes may have changed, so see what rake:routes says and get ready for a lot of search-and-replace
I did this for a client with a smallish site. First, version control is your friend. Make sure you have the entire codebase committed.
Next, the basic recipe is as follows
Tag the current source
Update to the next release of rails (you'll have to google for the release announcement). My app was frozen, so I just had to freeze to that version
rake rails:update to update the config, scripts and js
Diff your working copy against the version in your scm. Make any changes necessary for the app
Update any gems/plugins if necessary
Start the app, exercise and test. Look for deprecation notices
When it all looks good, commit to scm and tag
Lather, rinse, repeat
For my client's app, it was much easier than I thought.

How can I make my Ruby on Rails 2.3.4 application "Rails 3-ready"

I'm developing an application with Ruby on Rails that I want to maintain for at least a few years, so I'm concerned about the next version coming up soon.
Going from Rails 1 to Rails 2 was such a big pain that I didn't bother and froze my gems and let the application die, alone, in the dark.
On this project I don't want to do that. First because this new version looks awesome, but also because this application may turn into a real product.
How can I prepare my application so that it will be upgradable with as little changes as possible.
How time consuming do you think switching version will be?
And what about my server? Deployment?
I'm already looking at deprecation notices... what else can I do?
The best thing you could do would be to follow development of Rails 3 via blogs and the Github repository and keep up a copy of your app along with it.
The official Ruby on Rails blog is updated with "What's new in Edge" posts every once in awhile. There are other blogs that often write about new things in edge as well. Larger features are often highlighted in these blogs, so you know about all the cool new features you can play with.
I'm not sure how close Rails 3 is to release (last I heard the core team was talking about a release at RailsConf 2009 in May), but you can always freeze the edge version of Rails into your application and just see what breaks. If you are using git, or another DVCS, you might make a branch specifically for Rails 3 and periodically update Rails to the latest edge code. Just be aware that edge Rails is a moving target so things in your app may break or fix themselves as you are pulling in newer Rails code.
Update:
Jeremy McAnally has a ton of info on upgrading from Rails 2 to Rails 3 on his blog.
http://omgbloglol.com/
I don't think there is going to be a major problem. Going off what was said in that initial report the Rails team realized that they can't do a major rewrite like they did from 1 to 2.
They even say:
I’m sure there’ll be some parts of Rails 3 that are incompatible, but we’ll try to keep them to a minimum and make it really easy to convert a Rails 2.x application to Rails 3.
I would be more concerned going from Merb to Rails 3.
The single most important thing you can do to make it easy to migrate to a new version of rails is to have a comprehensive test suite. Without a good test suite, I would never have the confidence that the new version of rails hasn't broken something in my app. On the current Rails app I'm working on, we started on Rails 2.1.1 back in October of 2008. Since then, we've migrated to Rails 2.1.2, 2.2.2, 2.3.2, 2.3.3 and now 2.3.4. I did the migrations to 2.3.2, 2.3.3 and 2.3.4...and for the 2.3.2 and 2.3.3 upgrades, we had some failing tests that alerted us to problems we would not have discovered without having such a good test suite. The failing tests actually alerted us to a regressive bug in rails that there was a patch for on the Rails lighthouse but that was not included in the release (since it was discovered, right after the release).
Once you've got that test suite in place, just stay current with each rails release (waiting a couple weeks to upgrade is fine, just don't skip any of the releases).
Yehuda Katz (a member of the Rails core team) has stated that there will most likely be a transitional release, containing deprecation warnings and such.
So as long as you have a good test suite to expose the inevitable upgrade problems, and stay current with the Rails release, the migration to Rails 3 should not be too difficult.
As simple as:
One
Two
Three
Great screencasts from Ryan Bates.
For preparing your application, the best way it what Jared said. Follow the Rails3 development.
For the time consuming, I think it depends of how you've followed the rails3 development before it's release.
And for the deployment, it shouldn't take too much problems. Rails 3 will be using Rack. So you can start it with mongrel, passenger or any server/gateway it shouldn't give you any problem.
There are some major changes in Rails 3, I posted about my experience upgrading my app to Rails 3 here: http://rails3.community-tracker.com/permalinks/5/notes-from-the-field-upgrading-to-rails-3
A good start in preparing would be to migrate over to using bundler. And doing a very deep review of strings that will go through the new XSS protection scheme.
There are going to be some automated compatibility checkers. Also, keep an eye on http://www.railsplugins.org/ so that you know if the libraries you depend on are going to be upgraded. The Rails Core team seems to be giving a lot of advance notice to the community this time around, so any lib that is actively maintained should be good to go.
Just do one thing
take a backup of your old version project first and then
on terminal(command prompt) write
rails new path/of/the/project
for example if my 2.3.* project is at home/rails_projects/myproject then
rails new home/rails_projects/myproject
or
cd home/rails_projects
rails new myproject
It will ask if there is any modifications done in any /config or other files. Do appropriate.

Resources