1 – Problem Description
How to upgrade/update Rails 3.0.x to 3.1.x
2 – Solution
Anxious to upgrade? No worries, here are the steps after a painful weekend :)
Delete your Gemfile.lock from your app root folder and let bundler manage the new dependencies
cd path/to/my_rails_app rm Gemfile.lock
Remove all version strings from your gems and let bundler figure out the dependencies. For example,
gem ‘mysql2’, ‘0.2.17’ gem ‘devise’, ‘1.5.2’
gem 'mysql2' gem 'devise'
Update rails gem version and add support for the asset pipeline,
gem 'rails', '3.1.4' # Asset pipeline gem 'sass-rails' gem 'coffee-rails' gem 'uglifier' gem 'therubyracer' gem 'jquery-rails'
Before executing the following command make sure you have a backup of your app, as this will overwrite some files. Later you should get a diff and add your extra code in the new files.
bundle exec rake rails:update
Let’s double check now that everything is in place. If not add or remove accordingly.
- In config/application.rb add
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6
- In config/environments/development.rb add
1 2 3 4 5
- In config/environments/production.rb add
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
- In config/environments/test.rb add
1 2 3
Pipeline assets can be placed inside an application in one of three locations: **app/assets**, **lib/assets** or **vendor/assets**.
- This is a manifest file that’ll automatically include all the stylesheets available in this directory
- and any sub-directories. You’re free to add application-wide styles to this file and they’ll appear at
- the top of the compiled file, but it’s generally better to create a new file per style scope. = require_self = require_tree . */
Now, go and change all app/views files to include
instead of requiring multiple .css and .js files.
. Fix image references by replacing all
<%= image_tag "blahblah.png" %>
bundle exec rails s
should work now!
Some final tips.
In case you change to production environment, first precompile the assets by executing
bundle exec rake assets:precompile bundle exec rails s
If you have
gem ‘delayed_job’in your Gemfile, you should change it to
If you have
gem ‘devise’in your Gemfile, you should have a drink and go read the upgrade instructions  :P
Give me a hug :D
3 – References
 Asset pipeline