$30 off During Our Annual Pro Sale. View Details »

The Long Ball: Upgrading Rails from 1.2 -> 4.0

The Long Ball: Upgrading Rails from 1.2 -> 4.0

RailsConf 2013 - Explore tips to upgrade from each major version to the other, and how to efficiently tackle a 1.2 -> 4.0 upgrade through two different case studies.
The velocity of change for Rails versions has a side effect -- businesses hesitate to update to the latest version until their productivity drops and they're forced to update. What happens then? Let's explore a case study of a Rails app that followed this pattern.

Jesse Wolgamott

May 02, 2013
Tweet

More Decks by Jesse Wolgamott

Other Decks in Programming

Transcript

  1. The Long Ball:
    Upgrading Rails
    From 1.2 → 4.0
    Jesse Wolgamott | @jwo
    Thursday, May 2, 13

    View Slide

  2. Most Rails apps don't live as long as
    your entire career
    Thursday, May 2, 13

    View Slide

  3. but... what if they do?
    Thursday, May 2, 13

    View Slide

  4. Rails is not
    Wordpress and
    you cannot press
    "Upgrade".
    Thursday, May 2, 13

    View Slide

  5. In Rails, the code is
    changing constantly.
    Thursday, May 2, 13

    View Slide

  6. Thursday, May 2, 13

    View Slide

  7. And this is a good
    thing
    Thursday, May 2, 13

    View Slide

  8. •Features
    •Security Updates
    •End of Life
    Thursday, May 2, 13

    View Slide

  9. there are many Rails 2.3
    applications out there right
    now, chugging away and
    providing business value.
    Thursday, May 2, 13

    View Slide

  10. What should we
    do with them?
    Thursday, May 2, 13

    View Slide

  11. Life in a 1.x App
    Thursday, May 2, 13

    View Slide

  12. page.replace_html('tasks-completed',
    Task.completed_count)
    page.visual_effect(:highlight,
    'task-item-' + @task.id.to_s,
    :duration => 1.0)
    http://viget.com/extend/getting-started-with-rjs-in-rails
    Thursday, May 2, 13

    View Slide

  13. <%= link_to_remote 'Mark as Complete',
    :update =>, 'task-status-' + @task.id.to_s,
    :url => {:controller => 'task',
    :action => 'mark_complete',
    :id => @task
    }
    %>
    http://viget.com/extend/getting-started-with-rjs-in-rails
    Thursday, May 2, 13

    View Slide

  14. svn import . svn://localhost/blab -m "initial import" --
    username rbates
    cd ../
    svn co svn://localhost/blab/trunk blab
    cd blab
    cp config/database_example.yml config/database.yml
    svn propset svn:ignore database.yml config/
    svn propset svn:ignore "*" log/
    svn propset svn:ignore "*" tmp/
    http://railscasts.com/episodes/36-subversion-on-rails
    Thursday, May 2, 13

    View Slide

  15. Life in a 2.3 App
    Thursday, May 2, 13

    View Slide

  16. Rails::Initializer.run do |config|
    config.gem "haml"
    config.gem "chronic", :version => '0.2.3'
    config.gem "hpricot", :source => "http://
    code.whytheluckystiff.net"
    config.gem "aws-s3", :lib => "aws/s3"
    end
    rake gems:install
    http://archives.ryandaigle.com/articles/2008/4/1/what-s-
    new-in-edge-rails-gem-dependencies
    Thursday, May 2, 13

    View Slide

  17. User.find(:all, :limit => 1)
    User.find(:all)
    User.find(:first)
    User.first(:conditions => {:name => 'lifo'})
    User.all(:joins => :items)
    http://m.onkey.org/active-record-query-interface
    Thursday, May 2, 13

    View Slide

  18. How We
    Romanticize
    Rails 2.3
    Thursday, May 2, 13

    View Slide

  19. Life in a 3.0 App
    Thursday, May 2, 13

    View Slide

  20. Article.where("published_at <= ?", Time.now).includes(:comments)
    scope :published, lambda { where(published: true)}
    Article.first
    http://railscasts.com/episodes/202-active-record-queries-in-
    rails-3
    Thursday, May 2, 13

    View Slide

  21. class Person
    include ActiveModel::Validations
    attr_accessor :title
    validates :title, :presence => true
    end
    Thursday, May 2, 13

    View Slide

  22. Railscasts::Application.routes.draw do
    root :to => "episodes#index"
    resources :spam_checks
    resources :spam_reports do
    member do
    post :confirm
    end
    end
    end
    http://railscasts.com/episodes/226-upgrading-to-rails-3-
    part-2
    Thursday, May 2, 13

    View Slide

  23. Life in a 3.1 App
    Thursday, May 2, 13

    View Slide

  24. //= require jquery
    //= require jquery_ujs
    //= require_tree .
    http://guides.rubyonrails.org/asset_pipeline.html
    Thursday, May 2, 13

    View Slide

  25. /*
    *= require_self
    *= require_tree .
    */
    http://guides.rubyonrails.org/asset_pipeline.html
    Thursday, May 2, 13

    View Slide

  26. http://guides.rubyonrails.org/asset_pipeline.html
    Thursday, May 2, 13

    View Slide

  27. Life in a 3.2 App
    Thursday, May 2, 13

    View Slide

  28. • .pluck(:id)
    • Better all around (faster)
    • mass_assignment (attr_accessible)
    Thursday, May 2, 13

    View Slide

  29. Quick look at 4.0
    Thursday, May 2, 13

    View Slide

  30. • Wicked Awesome Postgres Features
    • Cooler Caching & strong_parameters
    • Turbolinks
    • Best Rails I’ve used
    Thursday, May 2, 13

    View Slide

  31. Upgrade by
    Rewrite
    Thursday, May 2, 13

    View Slide

  32. Upgrade by
    Refactor
    Thursday, May 2, 13

    View Slide

  33. The Decision to Rewrite
    is not a technical decision
    - it is a organizational
    decision
    Thursday, May 2, 13

    View Slide

  34. If you rewrite,
    you’ll likely fail
    Thursday, May 2, 13

    View Slide

  35. Fail to: Recreate
    every single
    feature
    Thursday, May 2, 13

    View Slide

  36. Fail to: Keep
    product
    momentum
    Thursday, May 2, 13

    View Slide

  37. Fail to: Show users
    you did anything
    worthwhile
    Thursday, May 2, 13

    View Slide

  38. When should you
    rewrite?
    Thursday, May 2, 13

    View Slide

  39. php on Rails
    Thursday, May 2, 13

    View Slide

  40. Vendored Rails /
    Gems
    Thursday, May 2, 13

    View Slide

  41. Instead: Rewrite
    by Refactoring
    Tiny Wins
    Thursday, May 2, 13

    View Slide

  42. The main upgrade
    pains
    Thursday, May 2, 13

    View Slide

  43. Rails 2.3 Rails 3.0 Rails 3.1 Rails 4.0
    Gems Router
    JavaScript
    Queries
    CSS
    JavaScript
    Forms
    Thursday, May 2, 13

    View Slide

  44. • Get to Rails 2.3 with bundler
    • Get to Rails 3.0 with Arel
    • Get to Rails 3.1 with Asset Pipeline
    • Get to Rails 4.0 with Gemfile
    updates
    Thursday, May 2, 13

    View Slide

  45. • Tip! use featured extracted gems
    during your 3.0 upgrade
    • prototype_rails
    • rails_autolink
    • deprecated_finders
    Thursday, May 2, 13

    View Slide

  46. Let's talk about
    Authentication
    Thursday, May 2, 13

    View Slide

  47. Thursday, May 2, 13

    View Slide

  48. Always be
    Upgrading
    Thursday, May 2, 13

    View Slide

  49. The Checklist
    Thursday, May 2, 13

    View Slide

  50. rails-upgrade-
    checklist.com
    Thursday, May 2, 13

    View Slide

  51. Thursday, May 2, 13

    View Slide

  52. Thursday, May 2, 13

    View Slide

  53. Thursday, May 2, 13

    View Slide

  54. @jwo
    Ruby o Rails
    rails-upgrade-
    checklist.com
    Thursday, May 2, 13

    View Slide