Slide 1

Slide 1 text

Updating to Rails 4 Bryce Kerley Miami Ruby Brigade October 21, 2013 Monday, October 21, 13

Slide 2

Slide 2 text

Bryce Kerley @bonzoesc Monday, October 21, 13

Slide 3

Slide 3 text

All of the Links http://bit.ly/rails4upd Monday, October 21, 13 You don’t have to struggle to write down all the links :)

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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.

Slide 6

Slide 6 text

Gemfile 1. Change rails version 2. Add protected_attributes 3. Remove assets group 4. Update the bundle Monday, October 21, 13

Slide 7

Slide 7 text

rails -gem 'rails', '~> 3.2.13' +gem 'rails', '~> 4.0.0' Monday, October 21, 13

Slide 8

Slide 8 text

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.

Slide 9

Slide 9 text

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.

Slide 10

Slide 10 text

bundle update Monday, October 21, 13

Slide 11

Slide 11 text

Configuration Eager Loading Session Encryption Whiny Nils Auto Explain Monday, October 21, 13

Slide 12

Slide 12 text

Eager Loading # Thread safety and eager loading changed # add to config/environments/*.rb + config.eager_load = false Monday, October 21, 13

Slide 13

Slide 13 text

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.

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Plugins Are Dead vendor/plugins should go away git rm vendor/plugins/.gitkeep Monday, October 21, 13

Slide 17

Slide 17 text

Fix What Broke Run integration tests Make them green Monday, October 21, 13

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Updating to Rails 4 1.Have integration tests 2.Update Gems 3.Update configuration 4.Fix brokenness Monday, October 21, 13

Slide 20

Slide 20 text

Links http://bit.ly/rails4upd Monday, October 21, 13