General upgrade approach

Get informationabout the changes and install the official rails_upgrade plugin. Run rake rails:upgrade:backup to backup important files. Then run rake rails:upgrade:check to analyse your project. The plugin displays useful information for various places where things need to be changed. It also has tasks for creating your Gemfile, updating your routes and configuration. But there is still some manual work required. I have written three little helper scripts that can assist you to solve some tasks.

When finished, replace some of the project’s Rails-specific files. You can do this by navigating to your project’s parent directory and running rails my_project_name as if you would want to create a new one. Then pick the files to overwrite.

Upgrade scripts

ERB syntax changes (the upgrade tasks complains about more, but this is wrong)

Add the config initializer to environment files

#!/usr/bin/env ruby# add the AppName::Application.configure command to all config/environments/* filesENVIRONMENTS_PATH='config/environments/'APPLICATION_PATH='config/application.rb'if!File.exist?ENVIRONMENTS_PATHraise'Please call the script from the Rails root directory'elsif!(File.exist?(APPLICATION_PATH)&&(File.read(APPLICATION_PATH)=~/module\s+(\w+)/)&&$1)raise"You need an already updated #{APPLICATION_PATH} to run this script"elseapp_name=$1Dir[ENVIRONMENTS_PATH+'*'].each{|filename|lines=File.readlinesfilenameunlesslines.join=~/#{app_name}::Application.configure/lines.map!{|l|''+l}lines.unshift"#{app_name}::Application.configure do"lines<<"end"File.open(filename,'w'){|file|file.printlines.join}end}puts:Doneend