Slide 1

Slide 1 text

Unboxing Rails 7 What’s new in the latest major version RailsConf 2022 speakerdeck.com/claudiob

Slide 2

Slide 2 text

Unboxing Rails 7

Slide 3

Slide 3 text

Unboxing Rails 7 Rafael Mendonça França Ryuta Kamizono Jean Boussier Eileen M. Uchitelle Jonathan Hefner Xavier Noria John Hawthorn Zachary Scott Jorge Manrubia Kasper Timm Hansen Alex Ghiculescu Petrik de Heus Eugene Kenny Gannon McGibbon David Heinemeier Hansson Andrew White Guillermo Iguaran John Bampton Yasuo Honda Aaron Patterson Abhay Nikam Sean Doyle Vipul A M Jacopo Beschi Santiago Bartesaghi Étienne Barrié Daniel Colson Ricardo Díaz Akira Matsuda Carlos Antonio da Silva John Crepezzi George Claghorn Ashik Salman Haroon Ahmed Aditya Bhutani Jacob Herrington Mike Dalessio Adrianna Chang alpaca-tc Breno Gazzola Dinah Shi André Luis Leal Cardoso Jr Henrik Nyh Jose Galisteo Sam Bostock Dima Fatko Adam Hess Nicholas Stuart Espartaco Palma Hartley McGuire Martin Jaime Okura Masafumi Roberto Miranda Benoit Daloze Mike Rogers Adam Hess Bogdan Denkovych Christian Schmidt Jamie McCarthy Leo Correa Ruby Active Support Active Model Active Storage Action View Active Record Railties 👏

Slide 4

Slide 4 text

12 - s.required_ruby_version = ">= 2.5.0" 12 + s.required_ruby_version = ">= 2.7.0" 6487836a Rails 7 requires Ruby 2.7 and prefer Ruby 3+ rails.gemspec 12 - gem "byebug" 12 + gem "debug", ">= 1.0.0.rc" #40914 Depend on ruby/debug, replacing Byebug Gemfile 29 - formats = formats.map(&:ref).compact 29 + formats = formats.filter_map(&:ref) #42053 Replace map + compact with filter_map actionpack/lib/action_controller/metal/rendering.rb Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties

Slide 5

Slide 5 text

Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties #41333 Add Enumerable#maximum User = Struct.new(:name, :age) users = [User.new("Alice", 42), User.new("Bob", 19), User.new("Charlie", 22)] users.maximum(:age) #=> 42 #40914 Add Enumerable#sole ["x"].sole #=> "x" Set.new.sole #=> Enumerable::SoleItemExpectedError: no item found { a: 1, b: 2 }.sole #=> Enumerable::SoleItemExpectedError: multiple items found User.where(admin: true).sole #=> #

Slide 6

Slide 6 text

Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties #41022 Add validate numericality in range class Adult < Person validate :age, numericality: { in: 18..99 } end #40095 Add ComparisonValidator to validate comparison of any objects class User < ApplicationRecord validates_comparison_of :birth_date, less_than_or_equal_to: -> { Date.today } validates_comparison_of :preferred_name, other_than: :given_name, allow_nil: true end

Slide 7

Slide 7 text

Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties #42410 Add support for ActiveStorage expiring URLs <%= image_tag rails_blob_path(user.avatar, expires_in: 5.minutes) %> #=> config.active_storage.urls_expire_in = 60.minutes # global #42425 Add audio analyzer to active storage ActiveStorage::Analyzer::AudioAnalyzer.new(blob).metadata #=> { duration: 5.0, bit_rate: 320340 }

Slide 8

Slide 8 text

#42234 Let link_to infer link name from Model#to_s <%= link_to @profile, @profile.name %> #=> Olivier #40914 Support sms_to options when name not specified <%= sms_to "5155555785", "Text me", body: "Help me" %> #=> Text me #41143 Support phone_to options when name not specified <%= phone_to "5155555785", "Phone me", country_code: "01" %> #=> Phone me Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties

Slide 9

Slide 9 text

Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties #41659 Add encryption to Active Record class Person < ApplicationRecord encrypts :email, :birth_date end #41372 Implement Relation#load_async to schedule the query on the background thread pool def index @categories = Category.some_complex_scope.load_async @posts = Post.some_complex_scope.load_async end

Slide 10

Slide 10 text

Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties #40249 Expose an invert_where method that will invert all scope conditions class User < ApplicationRecord scope :active, -> { where(accepted: true, locked: false) } end User.active # ... WHERE `accepted` = 1 AND `locked` = 0 User.active.invert_where # ... WHERE NOT (`accepted` = 1 AND `locked` = 0) #41439 Add #excluding to ActiveRecord::Relation Post.excluding(post_one, post_two) # SELECT "posts".* FROM "posts" WHERE "posts"."id" NOT IN (1, 2)

Slide 11

Slide 11 text

58 - <% if spring_install? -%> 59 - gem "spring" 60 - <% end -%> 59 + # gem "spring" #42997 Remove spring as a default installation option railties/lib/rails/generators/rails/app/templates/Gemfile.tt 58 - <% if depend_on_listen? -%> 59 - gem "listen", "~> 3.3" 60 - <% end -%> #42985 Stop trying to configure listen by default on compatible platforms railties/lib/rails/generators/rails/app/templates/Gemfile.tt Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties

Slide 12

Slide 12 text

- gem "webpacker", "~> 6.0.0", require: ENV["SKIP_REQUIRE_WEBPACKER"] != "true" 12 + gem "jsbundling-rails" #43172 Use the combined jsbundling-rails gem instead of individual js bundler gems Gemfile Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties > rails new app --javascript=rollup # options: rollup, webpack, esbuild, importmap > yarn build --watch # or ./bin/dev rollup v2.72.0 bundles app/javascript/application.js → app/assets/builds/application.js... waiting for changes...

Slide 13

Slide 13 text

16 - gem "sass-rails" #43110 Remove default reliance on Sass and CSS generators Gemfile Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties > rails new app --css=bulma # options: tailwind, bootstrap, bulma, postcss, sass > yarn build:css --watch # or ./bin/dev Sass is watching for changes. Press Ctrl-C to stop. 21 + gem "cssbundling-rails" 22 + gem "tailwindcss-rails" #43177 Add --css app generator option Gemfile

Slide 14

Slide 14 text

17 - gem "turbolinks", "~> 5" 17 + gem "stimulus-rails" 18 + gem "turbo-rails" 19 + gem "importmap-rails" #42999 Replace Webpacker with importmapped Hotwire as default JavaScript setup Gemfile Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties > rails new app # uses importmap, turbo, stimulus: Node is not required! > rails new app --webpack --skip-hotwire # uses webpack (useful for React) > rails new app --skip-javascript # nothing pre-configured

Slide 15

Slide 15 text

0d523d Drops support for classic mode (Zeitweirk only) Unboxing Rails 7 #42538 Generate less initializers in new/upgraded Rails apps #42240 Add Marginalia to Rails, via QueryLogs #43261 Make Sprockets more optional, offer Propshaft as alternative #39135 Add ability to use pre-defined Active Storage variants #43112 Document that @rails/ujs is deprecated #41856 Add support for generated columns in PostgreSQL #42245 Support NullsFirst for all databases #39723 Create database via UI when ActiveRecord::NoDatabaseError #40708 Change form_with to generate non-remote forms by default #41083 Avoid suggesting very unlikely changes in rails app:update

Slide 16

Slide 16 text

Unboxing Rails 7 What’s new in the latest major version RailsConf 2022 speakerdeck.com/claudiob 🙇