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

Unboxing Rails 7

Unboxing Rails 7

What’s new in the latest major version
See https://rubyonrails.org/2021/12/15/Rails-7-fulfilling-a-vision

---

Ruby
- 648783 | Rails 7 requires Ruby 2.7 and prefer Ruby 3+
- #42053 | Replace map + compact with filter_map
- #40914 | Depend on ruby/debug, replacing Byebug

Active Support
- #40914 | Add Enumerable#sole
- #41333 | Add Enumerable#maximum

Active Model
- #41022 | Add validate numericality in range
- #40095 | Add ComparisonValidator to validate comparison of any objects

Active Storage
- #42425 | Add audio analyzer to active storage
- #42410 | Add support for ActiveStorage expiring URLs

Action View
- #42234 | Let link_to infer link name from Model#to_s
- #41143 | Support phone_to options when name not specified
- #40914 | Support sms_to options when name not specified

Active Record
- #41659 | Add encryption to Active Record
- #41372 | Implement Relation#load_async to schedule the query on the background thread pool
- #41439 | Add #excluding to ActiveRecord::Relation
- #40249 | Expose an invert_where method that will invert all scope conditions

Railties
- #42997 | Remove spring as a default installation option
- #42985 | Stop trying to configure listen by default on compatible platforms
- #43172 | Use the combined jsbundling-rails gem instead of individual js bundler gems
- #43110 | Remove default reliance on Sass and CSS generators
- #43177 | Add --css app generator option
- #42999 | Replace Webpacker with importmapped Hotwire as default JavaScript setup

Other relevant PRs
- 0d523d | Drops support for classic mode (Zeitweirk only)
- #42240 | Add Marginalia to Rails, via QueryLogs
- #43261 | Make Sprockets more optional, offer Propshaft as alternative
- #39135 | 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
- #42538 | Generate less initializers in new/upgraded Rails apps

0722f1ff8d0a69bce57ebdb93dafc395?s=128

Claudio B.

May 11, 2022
Tweet

More Decks by Claudio B.

Other Decks in Programming

Transcript

  1. Unboxing Rails 7 What’s new in the latest major version

    RailsConf 2022 speakerdeck.com/claudiob
  2. Unboxing Rails 7

  3. 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 👏
  4. 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
  5. 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 #=> #<User id: 7, name: "Alice", admin: true>
  6. 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
  7. 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) %> #=> <img src="https://s3.amazonaws.com/bucket/avatar.jpg?X-Amz-Security- Token=FQIA1235&X-Amz-Credential=ASIAJF3BXG&X-Amz-Date=20170125T044127Z&X-Amz- Expires=60&X-Amz-Signature=24db053455"> 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 }
  8. #42234 Let link_to infer link name from Model#to_s <%= link_to

    @profile, @profile.name %> #=> <a href="/profiles/1">Olivier</a> #40914 Support sms_to options when name not specified <%= sms_to "5155555785", "Text me", body: "Help me" %> #=> <a href="sms:5551234567;?body=Help%20me">Text me</a> #41143 Support phone_to options when name not specified <%= phone_to "5155555785", "Phone me", country_code: "01" %> #=> <a href="tel:+015155555785">Phone me</a> Unboxing Rails 7 Ruby Active Support Active Model Active Storage Action View Active Record Railties
  9. 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
  10. 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)
  11. 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
  12. - 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...
  13. 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
  14. 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
  15. 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
  16. Unboxing Rails 7 What’s new in the latest major version

    RailsConf 2022 speakerdeck.com/claudiob 🙇