SlideShare a Scribd company logo
Upgrading to
                          Rails 3
 OSCON 2010
Thursday, July 22, 2010
Michael Bleigh
                 @mbleigh

 OSCON 2010
Thursday, July 22, 2010
Thursday, July 22, 2010
Jeremy McAnally’s
                          Rails Upgrade Handbook
                             bit.ly/railsupgrade
 OSCON 2010
Thursday, July 22, 2010
Rails 3 is
                          Different
 OSCON 2010
Thursday, July 22, 2010
Rails 3 is a
                          Bi     ange
 OSCON 2010
Thursday, July 22, 2010
Why the hell
                    should I bother?

 OSCON 2010
Thursday, July 22, 2010
Modularity

 OSCON 2010
Thursday, July 22, 2010
Rails 2.3 Stack
                               ActiveRecord


                               ActiveSupport


                              ActiveResource


                                ActionPack


                                 Test::Unit




 OSCON 2010
Thursday, July 22, 2010
Rails 3 Ecosystem
                                          DataMapper
                           ActiveRecord                     MongoMapper

                                          ActiveSupport


                               ActiveResource            ActiveModel


                                           ActionPack

                              RSpec                             Bacon
                                            Test::Unit




 OSCON 2010
Thursday, July 22, 2010
Rails 2.3 Controller

                          ActionController::Base


                          ApplicationController


                             YourController




 OSCON 2010
Thursday, July 22, 2010
Rails 3 Controller
                              AbstractController::Base


                              ActionController::Metal


                               ActionController::Base


                               ApplicationController


                                  YourController



 OSCON 2010
Thursday, July 22, 2010
Less Monkeypatching



 OSCON 2010
Thursday, July 22, 2010
Security
   darwinbell via Flickr

 OSCON 2010
Thursday, July 22, 2010
small change,
                          big impact

 OSCON 2010
Thursday, July 22, 2010
HTML is escaped
                            by default.


 OSCON 2010
Thursday, July 22, 2010
<!-- Rails 2.3 -->
                  <div class='comment'>
                    <%= comment.body %>
                  </div>

                  <!-- Rails 3 -->
                  <div class="comment">
                    <%= comment.body.html_safe %>
                  </div>

                  <!-- Rails 3 (alternate) -->
                  <div class="comment">
                    <%=raw comment.body %>
                  </div>



Thursday, July 22, 2010
It’s a good   thing.TM




 OSCON 2010
Thursday, July 22, 2010
New Apis

 OSCON 2010
Thursday, July 22, 2010
e Router

 OSCON 2010
Thursday, July 22, 2010
Rack Everywhere!


 OSCON 2010
Thursday, July 22, 2010
Fancy New DSL


 OSCON 2010
Thursday, July 22, 2010
More Powerful

 OSCON 2010
Thursday, July 22, 2010
# Rails 2.3
                  map.connect '/help', :controller => 'pages',
                                       :action => 'help'

                  # Rails 3
                  match '/help', :to => 'pages#help'

                  # Rails 2.3
                  map.resources :users do |users|
                    users.resources :comments
                  end

                  # Rails 3
                  resources :users do
                    resources :comments
                  end




Thursday, July 22, 2010
# Rails 2.3
                  with_options :path_prefix => 'admin',
                               :name_prefix => 'admin' do |admin|
                    admin.resources :users
                    admin.resources :posts
                  end

                  # Rails 3
                  namespace :admin
                    resources :users
                    resources :posts
                  end




Thursday, July 22, 2010
# Rails 3

                  constraints(:subdomain => 'api') do
                    resources :statuses
                    resources :friends
                  end

                  match '/hello', :to => lambda{ |env|
                    [200, {'Content-Type' => 'text/plain'}, 'Hello
                  World']
                  }

                  match '/other-site', :to => redirect('http://url.com')




Thursday, July 22, 2010
A ionMailer

 OSCON 2010
Thursday, July 22, 2010
It’s (mostly) just
                       a controller.

 OSCON 2010
Thursday, July 22, 2010
class Notifier < ActionMailer::Base
                    default :from => "mikel@example.org"

                    def welcome_email(user)
                      @name = user.name
                      attachments['terms.pdf'] = File.read(
                        Rails.root.join('docs/terms.pdf')
                      )
                      mail(:to => user.email, :subject => "G’day Mate!")
                    end
                  end




Thursday, July 22, 2010
class UsersController < ApplicationController
                    respond_to :html
                    def create
                      @user = User.new(params[:user])

                      Notifier.welcome_email(@user).deliver if @user.save
                      respond_with @user
                    end
                  end




Thursday, July 22, 2010
Bundler

 OSCON 2010
Thursday, July 22, 2010
Caution: Entering
                   Controversy

 OSCON 2010
Thursday, July 22, 2010
# Rails 2.3

                  # environment.rb
                  config.gem 'acts-as-taggable-on'
                  config.gem 'ruby-openid', :lib => false

                  # test.rb
                  config.gem 'rspec'
                  config.gem 'cucumber'



                  # Rails 3

                  # Gemfile
                  gem 'acts-as-taggable-on'
                  gem 'ruby-openid', :require => false

                  group :test do
                    gem 'rspec'
                    gem 'cucumber'
                  end




Thursday, July 22, 2010
Dependency
                           Resolver

 OSCON 2010
Thursday, July 22, 2010
A iveRelation

 OSCON 2010
Thursday, July 22, 2010
Like named scopes,
                     only more so.


 OSCON 2010
Thursday, July 22, 2010
# Rails 2.3

                  Book.all(
                    :conditions => {:author => "Chuck Palahniuk"},
                    :order => "published_at DESC",
                    :limit => 10
                  )

                  # Rails 3

                  Book.where(:author => "Chuck Palahniuk")
                      .order("published_at DESC").limit(10)




Thursday, July 22, 2010
Inherently
                          Chainable

Thursday, July 22, 2010
# Rails 3

                  def index
                    @books = Book.where(:author => params[:author])
                  if params[:author]
                    @books = @books.order(:title) if params[:sort] ==
                  'title'
                    respond_with @books
                  end




Thursday, July 22, 2010
# Rails 2.3

                  class Book
                    named_scope :written_by {|a| {:conditions => {:author => a}}}
                    named_scope :after {|d| {:conditions => ["published_on > ?", d]}}
                  # Rails 3

                  class Book
                    class << self
                      def written_by(name)
                        where(:author => name)
                      end

                      def after(date)
                        where(["published_on > ?", date])
                      end
                    end
                  end




Thursday, July 22, 2010
Be er H ks

 OSCON 2010
Thursday, July 22, 2010
Generators

 OSCON 2010
Thursday, July 22, 2010
config.generators do   |g|
                    g.orm                :mongomapper
                    g.test_framework     :rspec
                    g.integration_tool   :rspec
                  end

                  rails g model my_model




Thursday, July 22, 2010
Engines

 OSCON 2010
Thursday, July 22, 2010
#lib/your_plugin/engine.rb
                  require "your_plugin"
                  require "rails"

                  module YourPlugin
                    class Engine < Rails::Engine
                      engine_name :your_plugin
                    end
                  end



Thursday, July 22, 2010
Lots more...
                     railsdispatch.com
                 edgeguides.rubyonrails.org



 OSCON 2010
Thursday, July 22, 2010
But we’re already
                     on Rails 2.3!

 OSCON 2010
Thursday, July 22, 2010
How do we cope?


 OSCON 2010
Thursday, July 22, 2010
Ignore it all
                           and cheat.
                          github.com/rails/
                           rails_upgrade

 OSCON 2010
Thursday, July 22, 2010
Finds Key
                           Blockers:
                          Routes, Bundler,
                           application.rb

 OSCON 2010
Thursday, July 22, 2010
3 Step Process

 OSCON 2010
Thursday, July 22, 2010
Analyze Your App
                 rake rails:upgrade:check




 OSCON 2010
Thursday, July 22, 2010
Backup 2.3 Files
                 rake rails:upgrade:backup




 OSCON 2010
Thursday, July 22, 2010
Run Upgrades
                  rake rails:upgrade:routes
                  rake rails:upgrade:gems
                  rake rails:upgrade:configuration




 OSCON 2010
Thursday, July 22, 2010
Takeaways

 OSCON 2010
Thursday, July 22, 2010
Tests help.
                    Unfortunately, they
                       may not run.


Thursday, July 22, 2010
Don’t be afraid to
                            re-generate.


Thursday, July 22, 2010
Just take it one
                          problem at a time.


Thursday, July 22, 2010
estions?
                          @mbleigh   @intridea
                 github.com/mbleigh/upgrade-to-rails3


 OSCON 2010
Thursday, July 22, 2010

More Related Content

PDF
Filipino Grade 10 Learner's Module
PPT
Chapter 3B - Ser vs Estar
PDF
K to 12 - Grade 9 Filipino Learners Module
PDF
K to 12 - Filipino Learners Module
PDF
Nick Sieger-Exploring Rails 3 Through Choices
ZIP
Rails 3 (beta) Roundup
PDF
Rails 3 Beautiful Code
PDF
Hardcore Extending Rails 3 - From RailsConf '10
Filipino Grade 10 Learner's Module
Chapter 3B - Ser vs Estar
K to 12 - Grade 9 Filipino Learners Module
K to 12 - Filipino Learners Module
Nick Sieger-Exploring Rails 3 Through Choices
Rails 3 (beta) Roundup
Rails 3 Beautiful Code
Hardcore Extending Rails 3 - From RailsConf '10

Similar to Upgrading to Rails 3 (20)

PDF
12 hours to rate a rails application
PDF
Migrating Legacy Rails Apps to Rails 3
PDF
Rails 3 : Cool New Things
KEY
More to RoC weibo
PDF
Frozen Rails Slides
PDF
Rails 3 Beginner to Builder 2011 Week 8
PDF
Ruby on Rails at PROMPT ISEL '11
PDF
12 Hours To Rate A Rails Application
PDF
Vaporware To Awesome
PDF
Rails2 Pr
KEY
Rails Antipatterns | Open Session with Chad Pytel
PDF
Rails3 changesets
PDF
RailsAdmin - the right way of doing data administration with Rails 3
PDF
Railswaycon 2009 - Summary
PDF
Rails 4.0
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
PDF
PDF Ruby on Rails 3 Day BC
PDF
Rails入門與新人實戰經驗分享
PDF
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
PDF
Rails Intro & Tutorial
12 hours to rate a rails application
Migrating Legacy Rails Apps to Rails 3
Rails 3 : Cool New Things
More to RoC weibo
Frozen Rails Slides
Rails 3 Beginner to Builder 2011 Week 8
Ruby on Rails at PROMPT ISEL '11
12 Hours To Rate A Rails Application
Vaporware To Awesome
Rails2 Pr
Rails Antipatterns | Open Session with Chad Pytel
Rails3 changesets
RailsAdmin - the right way of doing data administration with Rails 3
Railswaycon 2009 - Summary
Rails 4.0
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
PDF Ruby on Rails 3 Day BC
Rails入門與新人實戰經驗分享
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Rails Intro & Tutorial
Ad

More from Michael Bleigh (10)

PDF
OmniAuth: From the Ground Up (RailsConf 2011)
PDF
OmniAuth: From the Ground Up
PDF
The Grapes of Rapid (RubyConf 2010)
PDF
Deciphering the Interoperable Web
PDF
The Present Future of OAuth
PDF
Node.js and Ruby
PDF
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)
PDF
Persistence Smoothie
PDF
Twitter on Rails
PDF
Hacking the Mid-End (Great Lakes Ruby Bash Edition)
OmniAuth: From the Ground Up (RailsConf 2011)
OmniAuth: From the Ground Up
The Grapes of Rapid (RubyConf 2010)
Deciphering the Interoperable Web
The Present Future of OAuth
Node.js and Ruby
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)
Persistence Smoothie
Twitter on Rails
Hacking the Mid-End (Great Lakes Ruby Bash Edition)
Ad

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
Dropbox Q2 2025 Financial Results & Investor Presentation
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MIND Revenue Release Quarter 2 2025 Press Release
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Upgrading to Rails 3

  • 1. Upgrading to Rails 3 OSCON 2010 Thursday, July 22, 2010
  • 2. Michael Bleigh @mbleigh OSCON 2010 Thursday, July 22, 2010
  • 4. Jeremy McAnally’s Rails Upgrade Handbook bit.ly/railsupgrade OSCON 2010 Thursday, July 22, 2010
  • 5. Rails 3 is Different OSCON 2010 Thursday, July 22, 2010
  • 6. Rails 3 is a Bi ange OSCON 2010 Thursday, July 22, 2010
  • 7. Why the hell should I bother? OSCON 2010 Thursday, July 22, 2010
  • 9. Rails 2.3 Stack ActiveRecord ActiveSupport ActiveResource ActionPack Test::Unit OSCON 2010 Thursday, July 22, 2010
  • 10. Rails 3 Ecosystem DataMapper ActiveRecord MongoMapper ActiveSupport ActiveResource ActiveModel ActionPack RSpec Bacon Test::Unit OSCON 2010 Thursday, July 22, 2010
  • 11. Rails 2.3 Controller ActionController::Base ApplicationController YourController OSCON 2010 Thursday, July 22, 2010
  • 12. Rails 3 Controller AbstractController::Base ActionController::Metal ActionController::Base ApplicationController YourController OSCON 2010 Thursday, July 22, 2010
  • 13. Less Monkeypatching OSCON 2010 Thursday, July 22, 2010
  • 14. Security darwinbell via Flickr OSCON 2010 Thursday, July 22, 2010
  • 15. small change, big impact OSCON 2010 Thursday, July 22, 2010
  • 16. HTML is escaped by default. OSCON 2010 Thursday, July 22, 2010
  • 17. <!-- Rails 2.3 --> <div class='comment'> <%= comment.body %> </div> <!-- Rails 3 --> <div class="comment"> <%= comment.body.html_safe %> </div> <!-- Rails 3 (alternate) --> <div class="comment"> <%=raw comment.body %> </div> Thursday, July 22, 2010
  • 18. It’s a good thing.TM OSCON 2010 Thursday, July 22, 2010
  • 19. New Apis OSCON 2010 Thursday, July 22, 2010
  • 20. e Router OSCON 2010 Thursday, July 22, 2010
  • 21. Rack Everywhere! OSCON 2010 Thursday, July 22, 2010
  • 22. Fancy New DSL OSCON 2010 Thursday, July 22, 2010
  • 23. More Powerful OSCON 2010 Thursday, July 22, 2010
  • 24. # Rails 2.3 map.connect '/help', :controller => 'pages', :action => 'help' # Rails 3 match '/help', :to => 'pages#help' # Rails 2.3 map.resources :users do |users| users.resources :comments end # Rails 3 resources :users do resources :comments end Thursday, July 22, 2010
  • 25. # Rails 2.3 with_options :path_prefix => 'admin', :name_prefix => 'admin' do |admin| admin.resources :users admin.resources :posts end # Rails 3 namespace :admin resources :users resources :posts end Thursday, July 22, 2010
  • 26. # Rails 3 constraints(:subdomain => 'api') do resources :statuses resources :friends end match '/hello', :to => lambda{ |env| [200, {'Content-Type' => 'text/plain'}, 'Hello World'] } match '/other-site', :to => redirect('http://url.com') Thursday, July 22, 2010
  • 27. A ionMailer OSCON 2010 Thursday, July 22, 2010
  • 28. It’s (mostly) just a controller. OSCON 2010 Thursday, July 22, 2010
  • 29. class Notifier < ActionMailer::Base default :from => "mikel@example.org" def welcome_email(user) @name = user.name attachments['terms.pdf'] = File.read( Rails.root.join('docs/terms.pdf') ) mail(:to => user.email, :subject => "G’day Mate!") end end Thursday, July 22, 2010
  • 30. class UsersController < ApplicationController respond_to :html def create @user = User.new(params[:user]) Notifier.welcome_email(@user).deliver if @user.save respond_with @user end end Thursday, July 22, 2010
  • 32. Caution: Entering Controversy OSCON 2010 Thursday, July 22, 2010
  • 33. # Rails 2.3 # environment.rb config.gem 'acts-as-taggable-on' config.gem 'ruby-openid', :lib => false # test.rb config.gem 'rspec' config.gem 'cucumber' # Rails 3 # Gemfile gem 'acts-as-taggable-on' gem 'ruby-openid', :require => false group :test do gem 'rspec' gem 'cucumber' end Thursday, July 22, 2010
  • 34. Dependency Resolver OSCON 2010 Thursday, July 22, 2010
  • 35. A iveRelation OSCON 2010 Thursday, July 22, 2010
  • 36. Like named scopes, only more so. OSCON 2010 Thursday, July 22, 2010
  • 37. # Rails 2.3 Book.all( :conditions => {:author => "Chuck Palahniuk"}, :order => "published_at DESC", :limit => 10 ) # Rails 3 Book.where(:author => "Chuck Palahniuk") .order("published_at DESC").limit(10) Thursday, July 22, 2010
  • 38. Inherently Chainable Thursday, July 22, 2010
  • 39. # Rails 3 def index @books = Book.where(:author => params[:author]) if params[:author] @books = @books.order(:title) if params[:sort] == 'title' respond_with @books end Thursday, July 22, 2010
  • 40. # Rails 2.3 class Book named_scope :written_by {|a| {:conditions => {:author => a}}} named_scope :after {|d| {:conditions => ["published_on > ?", d]}} # Rails 3 class Book class << self def written_by(name) where(:author => name) end def after(date) where(["published_on > ?", date]) end end end Thursday, July 22, 2010
  • 41. Be er H ks OSCON 2010 Thursday, July 22, 2010
  • 43. config.generators do |g| g.orm :mongomapper g.test_framework :rspec g.integration_tool :rspec end rails g model my_model Thursday, July 22, 2010
  • 45. #lib/your_plugin/engine.rb require "your_plugin" require "rails" module YourPlugin class Engine < Rails::Engine engine_name :your_plugin end end Thursday, July 22, 2010
  • 46. Lots more... railsdispatch.com edgeguides.rubyonrails.org OSCON 2010 Thursday, July 22, 2010
  • 47. But we’re already on Rails 2.3! OSCON 2010 Thursday, July 22, 2010
  • 48. How do we cope? OSCON 2010 Thursday, July 22, 2010
  • 49. Ignore it all and cheat. github.com/rails/ rails_upgrade OSCON 2010 Thursday, July 22, 2010
  • 50. Finds Key Blockers: Routes, Bundler, application.rb OSCON 2010 Thursday, July 22, 2010
  • 51. 3 Step Process OSCON 2010 Thursday, July 22, 2010
  • 52. Analyze Your App rake rails:upgrade:check OSCON 2010 Thursday, July 22, 2010
  • 53. Backup 2.3 Files rake rails:upgrade:backup OSCON 2010 Thursday, July 22, 2010
  • 54. Run Upgrades rake rails:upgrade:routes rake rails:upgrade:gems rake rails:upgrade:configuration OSCON 2010 Thursday, July 22, 2010
  • 56. Tests help. Unfortunately, they may not run. Thursday, July 22, 2010
  • 57. Don’t be afraid to re-generate. Thursday, July 22, 2010
  • 58. Just take it one problem at a time. Thursday, July 22, 2010
  • 59. estions? @mbleigh @intridea github.com/mbleigh/upgrade-to-rails3 OSCON 2010 Thursday, July 22, 2010