Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Upgrading to Rails 4

Upgrading to Rails 4

From Miami Ruby Brigade Oct. 21 2013

Bryce "BonzoESC" Kerley

October 21, 2013
Tweet

More Decks by Bryce "BonzoESC" Kerley

Other Decks in Programming

Transcript

  1. All of the Links http://bit.ly/rails4upd Monday, October 21, 13 You

    don’t have to struggle to write down all the links :)
  2. Rails Guides Rails 4.0 Release Notes http://guides.rubyonrails.org/4_0_release_notes.html Upgrading Ruby on

    Rails http://guides.rubyonrails.org/upgrading_ruby_on_rails.html Monday, October 21, 13
  3. Integration Tests Do not upgrade if you can’t tell if

    your app works or not Monday, October 21, 13 We’ll be talking about integration testing in November.
  4. Gemfile 1. Change rails version 2. Add protected_attributes 3. Remove

    assets group 4. Update the bundle Monday, October 21, 13
  5. protected_attributes gem 'protected_attributes' Monday, October 21, 13 Rails 4 uses

    “strong parameters” instead of “protected attributes.” You can switch, but protected attributes still work if you pull in the gem.
  6. assets -group :assets do - gem 'sass-rails', '~> 3.2.3' -

    gem 'coffee-rails', '~> 3.2.1' - gem 'bourbon' - gem 'uglifier', '>= 1.0.3' -end +gem 'sass-rails', '~> 4.0.0' +gem 'coffee-rails', '~> 4.0.0' +gem 'bourbon' +gem 'uglifier', '>= 1.0.3' Monday, October 21, 13 There’s no more “assets” group in the Rails 4 gemfile.
  7. Eager Loading # Thread safety and eager loading changed #

    add to config/environments/*.rb + config.eager_load = false Monday, October 21, 13
  8. Session Encryption # Cookie encryption got better but you have

    # to ask for it in # config/initializers/secret_token.rb # If you leave secret_token existing sessions # will be upgraded in place MyApp::Application.config.secret_token = 'p09m345n' +MyApp::Application.config.secret_key_base = ‘atelkjetq’ Monday, October 21, 13 Rails 3 signed but didn’t encrypt session cookies. Rails 4 encrypts then signs, which is more secure.
  9. Whiny Nils # Remove from config/environments/*.rb # …and fix your

    code that calls methods on nil - # Log error messages when you - # accidentally call methods on nil. - config.whiny_nils = true Monday, October 21, 13
  10. Auto Explain # Remove from config/environments/*.rb # and enable your

    database’s slow query log # https://wiki.postgresql.org/wiki/Logging_Difficult_Queries - # Log the query plan for queries - # taking more than this (works - # with SQLite, MySQL, and - # PostgreSQL) - config.active_record.auto_explain_threshold_in_seconds = 0.5 Monday, October 21, 13
  11. Querying with SQL class Team def self.for_scoreboard(current_team) - rows =

    connection.select_all <<-SQL + rows = connection.select_all(<<-SQL).to_a SELECT t.id AS team_id, t.name AS team_name, … Monday, October 21, 13 Connection#select_all returns a Relation object now, and your existing code probably wants an Array
  12. Updating to Rails 4 1.Have integration tests 2.Update Gems 3.Update

    configuration 4.Fix brokenness Monday, October 21, 13