Upgrading to Rails 3
-
Upload
shivasubramanian-ananthanarayanan -
Category
Technology
-
view
13 -
download
1
Transcript of Upgrading to Rails 3
Upgrading to Rails 3
A Shivasubramanian
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
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
.rhtml to .erb
The Rails module
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!
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
Rails commands...Create a new application
Rails 2.xrails directory_path
Rails 3.xrails new app_name
Rails frameworks
config.frameworks Rails 2
ActionMailer ActionPack ActiveRecord ActiveResource ActiveSupport Railties
Rails frameworks...
config.frameworks Rails 3
ActionMailer ActionPack ActiveRecord ActiveResource ActiveSupport Railties ActionModel
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.
The Rails Application object...
The Rails Application object...Impact on config/routes.rb
Rails 2
Rails 3
The Rails Application object...Impact on config/environment.rb
Rails 2
Rails 3
The Rails Application object...Impact on config/environments/*.rb
Rails 2
The Rails Application object...Impact on config/environments/*.rb
Rails 3
Rails concerns
ActiveSupport::Concern Used to add extra functionality to Ruby/Rails
classes.
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
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
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
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
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