Wednesday, December 15, 2010

upgrade existing ruby on rails application with rails 3 0 0 and ruby 1 9 2p0


Upgrade existing ruby on rails application with rails 3.0.0 and ruby 1.9.2p0

Run your existing ruby on rails application with rails 3.0.0 and ruby 1.9.2p0.
1. Using rvm install ruby 1.9.2p0 and rails 3.0.0.
After installation you have to check ruby version by ruby -v and than upgrade system by rvm system.
2. You need to change the structure of existing rails application to rails 3.
– Firstly you unfreeze your existing rails by rake rails:unfreeze.
– Install plugin script/plugin install git://github.com/rails/rails_upgrade.git to upgrade your existing app.
– Now run rake rails:upgrade:check than rake rails:upgrade:backup to backup existing rails files.
– As per rails 3 you need to modify below listed files.
1. Script folder replace with current rails.
2. Add config/application.rb
3. Set config/environment.rb as per requirement.
Below is the sample for this:
# Load the rails application
require File.expand_path(‘../application’, __FILE__)
# Initialize the rails application
ApplicationName::Application.initialize!
4. Set environments/development.rb & test.rb
5. Change boot.rb as per rails 3.
Below is the sample for this:
require ‘rubygems’
# Set up gems listed in the Gemfile.
gemfile = File.expand_path(‘../../Gemfile’, __FILE__)
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require ‘bundler’
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts “Try running `bundle install`.”
exit!
end if File.exist?(gemfile)
6. Add config.ru.
Below is the sample for this:
require ::File.expand_path(‘../config/environment’, __FILE__)
run ApplicationName::Application
7. Add Gemfile – List set of required gem for your application.
Below is the sample for this:
source ‘http://rubygems.org’
source ‘http://gems.github.com’
gem ‘rails’, ’3.0.0′
gem “will_paginate”, :git => “git://github.com/mislav/will_paginate.git”, :branch => “rails3″
gem ‘sqlite3-ruby’, :require => ‘sqlite3′ # ‘lib’ option of rails 2.x is replaced with ‘require’ in rails 3
8. Replace Rakefile as per rails 3.
9. Add README for the rails 3.
10. Change routes.rb as per rails 3.
Eg. map.root :controller=> “login” in rails 2
root :to => “login#index” in rails 3
For more information just refer – http://asciicasts.com/episodes/203-routing-in-rails-3
3. Now you need to install all required gem by running bundle:install
4. Now bundle install successfully than run your application by rails s.
replace command for rails 3 against rails 2.x
script/console – rails c
script/server – rails s
5. If you phase the deprecation warning than just follow the instruction provided with it.
Below is the list of depreciated objects:
– Callback replaced with Base.callback :method => ‘name’
eg. after_initialize in rails 2.x is replaced with Base.after_initialize :method => ‘prefix_method’
– RAILS_ROOT replace with Rails.root.to_s.
– RAILS_ENV replace with Rails.env
– Verify method is replace with rails plugin install git://github.com/rails/verification.git
– Base.named_scope is replace with Base.scope.
– AppMailer.deliver_method_name is replace with AppMailer.method_name.deliver.
– error_messages_for was removed from Rails and is now available as a plugin.
rails plugin install git://github.com/rails/dynamic_form.git
– RAILS_DEFAULT_LOGGER is replace with Rails.logger
– Error for invalid multibyte char (US-ASCII) – solution is encoding utf-8
Hope this article help you out to upgrade your existing rails application with rails 3.

No comments:

Post a Comment