Upgrading Rails

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Upgrading Rails

Experiences and tips for upgrading Rails versions.

Nathan Youngman

June 17, 2014

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

20 slides
  1. porting to Rails 4 • Sometimes the new code still

    works in Rails 3:
 
 scope :sorted, order(“updated_at")
 
 scope :sorted, -> { order("updated_at") } • What if it doesn’t? Branch?
  2. dual-boot # Gemfile ! module ::Kernel
 def rails4?
 ENV["RAILS4"]
 end


    end
 if rails4?
 # monkey patch Bundler to support multiple lock files…
 # https://github.com/discourse/discourse/blob/master/Gemfile
 end RAILS4=1 rails s
  3. rails4? # Gemfile
 
 if rails4?
 gem "rails", “4.0.5" #

    protected_attributes, etc.
 else
 gem "rails", "3.2.18"
 end 
 # config/environments/test.rb
 
 ActiveSupport::Deprecation.silenced = true if rails4?

  4. incremental progress • Boot Server • Run Tests (Rails 3

    & 4) • Passing Tests • QA • Switch Default Rails
  5. whoops • Non-digest images in emails, use public/ • Blocks

    iframe embedding
 response.headers.except! ‘X-Frame-Options' • Endpoints
 protect_from_forgery exceptions (CSRF)
 xml_data = Hash.from_xml(request.body.read) • Threading bug in activerecord-session_store
  6. if rails_master?
 # gem "rails", :github => "rails/rails", :branch =>

    "4-1-stable"
 gem "rails", "4.1.2.rc2"
 else
 gem "rails", "4.0.5"
 end
  7. porting to Rails 3 • Prerequisite: Bundler
 http://bundler.io/v1.6/rails23.html • Boot

    server and run tests in an evening.
 Still a long ways to go.
  8. Gemfile # Gemfile
 module ::Kernel
 def rails3?
 ENV["RAILS3"]
 end
 end

    ! if rails3?
 gem 'rails', '3.0.20'
 gem 'prototype_legacy_helper', '0.0.0', :github => 'rails/ prototype_legacy_helper'
 else
 gem 'rails', ‘2.3.18' gem 'fake_arel'
 end
  9. booting # environment.rb
 
 if rails3?
 require File.expand_path('../environment3', __FILE__)
 else


    require File.expand_path('../environment2', __FILE__)
 end
 # boot.rb ! if rails3?
 puts "Booting Rails 3..."
 require File.expand_path('../boot3', __FILE__)
 else
 puts "Booting Rails 2..."
 require File.expand_path('../boot2', __FILE__)
 end
  10. server # config.ru ! require ::File.expand_path('../config/environment', __FILE__)
 
 if rails3?


    run FAVAdb::Application
 else
 use Rails::Rack::LogTailer
 use Rails::Rack::Static
 run ActionController::Dispatcher.new
 end
 # script/server ! #!/usr/bin/env ruby
 puts "Booting Rails 2..."
 require File.dirname(__FILE__) + '/../config/boot2'
 require 'commands/server'
  11. routes & configure # boot.rb ! def draw_routes(&block)
 if rails3?


    FAVAdb::Application.routes.draw(&block)
 else
 ActionController::Routing::Routes.draw(&block)
 end
 end
 
 def configure(&block)
 if rails3?
 FAVAdb::Application.configure(&block)
 else
 yield
 end
 end
  12. a plan • Boot Rails 3 • Click around until

    it breaks • (Capybara) tests for that section • Passing on Rails 2 & 3 • Repeat
  13. long-term • Rails 3.0 • JQuery • Rails 3.2 and

    the asset pipeline • Ruby 1.9+ with sufficient test coverage • Strong parameters • Rails 4.x

More Decks by Nathan Youngman

Other Decks in Technology