Download - Upgrading to Rails 3
![Page 1: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/1.jpg)
Upgrading to Rails 3
A Shivasubramanian
![Page 2: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/2.jpg)
What’s new in Rails 3?
Merb merges with Rails Major design changes
Clean separation of responsibilities Hooks for customizing Rails behaviour
Not backwards compatible
![Page 3: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/3.jpg)
Default method for dependency management Gemfile & Gemfile.lock Convert plugins to gems
Plugins – deprecated from Rails 3.2 onwards Bundler works in Rails 2.x with code customizations
Stick to Bundler v1.0.x Remove config.gem calls Remove customizations when moving to Rails 3.
Bundler
![Page 4: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/4.jpg)
.rhtml to .erb
![Page 5: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/5.jpg)
The Rails module
![Page 6: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/6.jpg)
Rails default files
config/preinitializer.rb config/application.rb Only 1 file in script/
script/rails – Represents the rails command
All other files removed – arguments to rails Other default files
Some files’ content have changed in Rails 3 Check for any customizations to default files!
![Page 7: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/7.jpg)
Rails commandsRails 2 command Rails 3 equivalent
./script/console rails console
./script/dbconsole rails dbconsole
./script/destroy rails destroy
./script/generate rails generate
./script/plugin rails plugin
./script/server rails server
./script/about rails about
![Page 8: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/8.jpg)
Rails commands...Create a new application
Rails 2.xrails directory_path
Rails 3.xrails new app_name
![Page 9: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/9.jpg)
Rails frameworks
config.frameworks Rails 2
ActionMailer ActionPack ActiveRecord ActiveResource ActiveSupport Railties
![Page 10: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/10.jpg)
Rails frameworks...
config.frameworks Rails 3
ActionMailer ActionPack ActiveRecord ActiveResource ActiveSupport Railties ActionModel
![Page 11: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/11.jpg)
The Rails Application object
Rails::Application config/application.rb Contains all settings global to your app
Move global settings from config/environment.rb
Other settings belong either in config/environment.rb (or) in individual environment files.
![Page 12: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/12.jpg)
The Rails Application object...
![Page 13: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/13.jpg)
The Rails Application object...Impact on config/routes.rb
Rails 2
Rails 3
![Page 14: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/14.jpg)
The Rails Application object...Impact on config/environment.rb
Rails 2
Rails 3
![Page 15: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/15.jpg)
The Rails Application object...Impact on config/environments/*.rb
Rails 2
![Page 16: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/16.jpg)
The Rails Application object...Impact on config/environments/*.rb
Rails 3
![Page 17: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/17.jpg)
Rails concerns
ActiveSupport::Concern Used to add extra functionality to Ruby/Rails
classes.
![Page 18: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/18.jpg)
Rails concerns...How to customize Rails functionality? (old style)
module A#add my methods
end
class SomeRailsClass include Aend
module A# add my methods
end
class SomeRailsClass extend Aend
class SomeRailsClass# add my methods
end
![Page 19: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/19.jpg)
Rails concerns...How to customize Rails functionality? (old style)
module Amodule ClassMethods
# add all class methods hereendmodule InstanceMethods
# add all instance methods hereenddef self.included(base)
base.send :include, InstanceMethodsbase.send :extend, ClassMethods
endend
![Page 20: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/20.jpg)
Rails concerns...How to customize Rails functionality? (old style)
Disadvantages:Not easy to find what customizations have been done
With include, you don’t need InstanceMethods
With extend, you don’t need ClassMethodsHard to find monkeypatching
![Page 21: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/21.jpg)
Rails concerns...How to customize Rails functionality? (new style)
module Aextend ActiveSupport::Concern
module ClassMethods# add my class methods here
end
module InstanceMethods# add my instance methods
hereend
end
![Page 22: Upgrading to Rails 3](https://reader034.vdocuments.us/reader034/viewer/2022051520/5886d1031a28ab776a8b47cb/html5/thumbnails/22.jpg)
Rails concerns...How to customize Rails functionality? (new style)
Advantages:Easy to find what customizations have been done – search for ActiveSupport::Concern
You still have to include the moduleInstanceMethods module no longer a requirement from Rails 3.2