What's coming in Rails 5.2, and sneak peek into Rails 6

What's coming in Rails 5.2, and sneak peek into Rails 6

The next minor version of Ruby on Rails is right around the corner! Let's look at those new features that are coming in the next few weeks to Rails 5.2, and sneak peek into those new features that will come in Rails 6.0, the next major release of Rails.

Presented at Great Western Rails #3 in Bristol, UK on March 21, 2018 and Tokyo Rubyist Meetup on Apr 4, 2018.

F1c4a3bb1606cc4a61711e61e2fe6146?s=128

Prem Sichanugrist

March 20, 2018
Tweet

Transcript

  1. What's coming in Rails 5.2 and sneak peek into Rails

    6 #rails52
  2. Prem Sichanugrist @sikachu /sikachu #rails52

  3. None
  4. Pull Request Link https://github.com/rails/rails/pull/25992 #rails52

  5. #tag #rails52 https://github.com/rails/rails/pull/25992

  6. 5.2 #rails52

  7. New Features Custom Mailer Delivery Job H2 Early Hints Headless

    Chrome and Headless Firefox Support DSL for Configuring CSP Header Verbose Query Log One-Way Migration in change block Active Storage Built-in Redis Cache Store ActiveSupport::CurrentAttributes #rails52
  8. Improvements Recycle Cache Keys AEAD Encrypted Cookies Support pg 1.0

    Safer Raw SQL handling New Threshold for Cache Compression freeze_time Bootsnap in Default Gemfile #rails52
  9. Active Storage #rails52

  10. NEW Active Storage #rails52

  11. NEW Active Storage #rails52 class User < ApplicationRecord # Associates

    an attachment and a blob. When the user # is destroyed they are purged by default (models # destroyed, and resource files deleted). has_one_attached :avatar end class AvatarsController < ApplicationController def update # params[:avatar] contains a # ActionDispatch::Http::UploadedFile object Current.user.avatar.attach(params.require(:avatar)) redirect_to Current.user end end
  12. NEW Active Storage #rails52 Direct Uploads

  13. NEW Active Storage #rails52 # Sprockets (Asset Pipeline) //= require

    activestorage # Yarn/Webpacker import * as ActiveStorage from "activestorage" ActiveStorage.start() # View file <%= form.file_field :attachments, multiple: true, direct_upload: true %>
  14. NEW Active Storage Q: Should I switch to Active Storage

    from [___________]? #rails52
  15. NEW Active Storage Q: Should I switch to Active Storage

    from [___________]? A: Sure!* #rails52
  16. NEW Active Storage Q: Should I use Active Storage for

    my new project? #rails52
  17. NEW Active Storage Q: Should I use Active Storage for

    my new project? A: Yes. #rails52
  18. Recycle Cache Keys #rails52 https://github.com/rails/rails/pull/29092

  19. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1-20180320190000"

  20. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1-20180320190000" post.update!({ ...

    }) post.cache_key #=> "post/1-20180320190013"
  21. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1-20180320190000" post.update!({ ...

    }) post.cache_key #=> "post/1-20180320190013" post.update!({ ... }) post.cache_key #=> "post/1-20180320190025"
  22. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1-20180320190000" post.update!({ ...

    }) post.cache_key #=> "post/1-20180320190013" post.update!({ ... }) post.cache_key #=> "post/1-20180320190025" post.update!({ ... }) post.cache_key #=> "post/1-20180320190102"
  23. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1-20180320190000" post.update!({ ...

    }) post.cache_key #=> "post/1-20180320190013" post.update!({ ... }) post.cache_key #=> "post/1-20180320190025" post.update!({ ... }) post.cache_key #=> "post/1-20180320190102" post.update!({ ... }) post.cache_key #=> "post/1-20180320190130"
  24. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1-20180320190000" post.update!({ ...

    }) post.cache_key #=> "post/1-20180320190013" post.update!({ ... }) post.cache_key #=> "post/1-20180320190025" post.update!({ ... }) post.cache_key #=> "post/1-20180320190102" post.update!({ ... }) post.cache_key #=> "post/1-20180320190130"
  25. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys "post/3-20180319190000" "post/5-20180317014200" Redis

  26. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys "post/1-20180320190013" "post/3-20180319190000" "post/5-20180317014200" Redis

  27. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys "post/1-20180320190025" "post/1-20180320190013" "post/3-20180319190000" "post/5-20180317014200" Redis

  28. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys "post/1-20180320190102" "post/1-20180320190025" "post/1-20180320190013" "post/3-20180319190000" "post/5-20180317014200"

    Redis
  29. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys "post/1-20180320190130" "post/1-20180320190102" "post/1-20180320190025" "post/1-20180320190013" "post/3-20180319190000"

    "post/5-20180317014200" Redis
  30. ♻ #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys

  31. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1" post.cache_version #=>

    "20180320190000"
  32. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1" post.cache_version #=>

    "20180320190000" post.update!({ ... }) post.cache_key #=> "post/1" post.cache_version #=> "20180320190013"
  33. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys post.cache_key #=> "post/1" post.cache_version #=>

    "20180320190000" post.update!({ ... }) post.cache_key #=> "post/1" post.cache_version #=> "20180320190013" post.update!({ ... }) post.cache_key #=> "post/1" post.cache_version #=> "20180320190025"
  34. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys "post/1" "post/3" "post/5" Redis

  35. #rails52 https://github.com/rails/rails/pull/29092 Recycle Cache Keys config.active_record.cache_versioning = true

  36. AEAD Encrypted Cookies #rails52 https://github.com/rails/rails/pull/28132

  37. AEAD Authenticated Encryption with Associated Data #rails52 https://github.com/rails/rails/pull/28132 AEAD Encrypted

    Cookies
  38. Rails 4 AES in CBC mode with HMAC using SHA1

    #rails52 https://github.com/rails/rails/pull/28132 AEAD Encrypted Cookies
  39. Rails 4 AES in CBC mode with HMAC using SHA1

    Rails 5.2 AES-GCM #rails52 https://github.com/rails/rails/pull/28132 AEAD Encrypted Cookies
  40. Benefits of AES-GCM #rails52 https://github.com/rails/rails/pull/28132 AEAD Encrypted Cookies

  41. Benefits of AES-GCM Faster encryption/decryption #rails52 https://github.com/rails/rails/pull/28132 AEAD Encrypted Cookies

  42. Benefits of AES-GCM Faster encryption/decryption Shorter ciphertext #rails52 https://github.com/rails/rails/pull/28132 AEAD

    Encrypted Cookies
  43. #rails52 https://github.com/rails/rails/pull/28132 AEAD Encrypted Cookies config.action_dispatch. use_authenticated_cookie_encryption = true

  44. H2 Early Hints Support #rails52 https://github.com/rails/rails/pull/30744

  45. Rails 5.2 + Puma + h2o #rails52 https://github.com/rails/rails/pull/30744 H2 Early

    Hints Support
  46. #rails52 https://github.com/rails/rails/pull/30744 H2 Early Hints Support HTTP/1.1 103 Early Hints

    Link: </application.css>; rel=preload; as=style Link: </application.js>; rel=preload; as=script HTTP/1.1 200 OK Date: Tue, 20 Mar 2018 15:12:00 GMT Content-Length: 4200 Content-Type: text/html; charset=utf-8 Link: </application.css>; rel=preload; as=style Link: </application.js>; rel=preload; as=script
  47. #rails52 https://github.com/rails/rails/pull/30744 H2 Early Hints Support <%= preload_link_tag "application.css" %>

    <link rel="preload" href="/assets/application.css" as="style" type="text/css" />
  48. #rails52 https://github.com/rails/rails/pull/30744 H2 Early Hints Support http://eileencodes.com/posts/http2-early-hints/

  49. DSL for Configuring CSP Header #rails52 https://github.com/rails/rails/pull/31162

  50. Content-Security-Policy Control access to content from a user-agent #rails52 https://github.com/rails/rails/pull/31162

    DSL for Configuring CSP Header
  51. #rails52 https://github.com/rails/rails/pull/31162 DSL for Configuring CSP Header #config/initializers/content_security_policy.rb Rails.application.config.content_security_policy do

    |p| p.default_src :self, :https p.font_src :self, :https, :data p.img_src :self, :https, :data p.object_src :none p.script_src :self, :https p.style_src :self, :https, :unsafe_inline # Specify URI for violation reports # p.report_uri "/csp-violation-report-endpoint" end
  52. #rails52 https://github.com/rails/rails/pull/31162 DSL for Configuring CSP Header # Override policy

    inline class PostsController < ApplicationController content_security_policy do |p| p.upgrade_insecure_requests true end end
  53. MDN web docs https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy #rails52 https://github.com/rails/rails/pull/31162 DSL for Configuring CSP

    Header
  54. Verbose Query Log #rails52 https://github.com/rails/rails/pull/26815

  55. #rails52 https://github.com/rails/rails/pull/26815 Started GET "/news/popular" for ::1 at 2016-10-19 00:5

    Processing by NewsController#popular as HTML Version Load (57.3ms) SELECT "versions".* FROM "ve Verbose Query Log
  56. #rails52 https://github.com/rails/rails/pull/26815 Started GET "/news/popular" for ::1 at 2016-10-19 00:5

    Processing by NewsController#popular as HTML Version Load (57.3ms) SELECT "versions".* FROM "ve ↳ app/views/news/show.html.erb:9:in `_app_views_news Verbose Query Log
  57. #rails52 https://github.com/rails/rails/pull/26815 Started GET "/news/popular" for ::1 at 2016-10-19 00:5

    Processing by NewsController#popular as HTML Version Load (57.3ms) SELECT "versions".* FROM "ve ↳ app/views/news/show.html.erb:9:in `_app_views_news Verbose Query Log
  58. #rails52 https://github.com/rails/rails/pull/26815 config.active_record.verbose_query_logs = true Verbose Query Log

  59. ActiveSupport::CurrentAttributes #rails52 https://github.com/rails/rails/pull/29180

  60. Subdomain.current Account.current #rails52 https://github.com/rails/rails/pull/29180 ActiveSupport::CurrentAttributes

  61. #rails52 https://github.com/rails/rails/pull/29180 ActiveSupport::CurrentAttributes class Subdomain < ApplicationRecord cattr_accessor :current #

    end class Account < ApplicationRecord def self.current $current_account # end end
  62. #rails52 https://github.com/rails/rails/pull/29180 ActiveSupport::CurrentAttributes # app/models/current.rb class Current < ActiveSupport::CurrentAttributes attribute

    :subdomain attribute :account end
  63. Current.subdomain Current.account #rails52 https://github.com/rails/rails/pull/29180 ActiveSupport::CurrentAttributes

  64. Thread-Isolated Storage Thread.current[_____] #rails52 https://github.com/rails/rails/pull/29180 ActiveSupport::CurrentAttributes

  65. #rails52 https://github.com/rails/rails/pull/29180 ActiveSupport::CurrentAttributes

  66. #rails52

  67. Built-in Redis Cache Store config.cache_store = :redis_cache_store #rails52 https://github.com/rails/rails/pull/31134

  68. New Threshold for Cache Compression Automatically compress value > 1kB

    #rails52 https://github.com/rails/rails/pull/31147
  69. freeze_time Shorthand for travel_to Time.current #rails52 https://github.com/rails/rails/pull/29681

  70. Bootsnap in Default Gemfile Add gem "bootsnap" for current projects

    #rails52 https://github.com/rails/rails/pull/29313
  71. Headless Chrome Headless Firefox #rails52 https://github.com/rails/rails/pull/30876
 https://github.com/rails/rails/pull/31365

  72. #rails52 https://github.com/rails/rails/pull/30876
 https://github.com/rails/rails/pull/31365 driven_by :selenium, using: :headless_chrome driven_by :selenium, using:

    :headless_firefox Headless Chrome & Firefox
  73. Custom Mailer Delivery Job #rails52 https://github.com/rails/rails/pull/29457

  74. #rails52 https://github.com/rails/rails/pull/29457 class MyMailer < ApplicationMailer self.delivery_job = MyCustomDeliveryJob end

    Custom Mailer Delivery Job
  75. 5.2 #rails52

  76. 6.0 #rails6

  77. #rails6 >= 2.4.1

  78. .create_or_find_by Use Unique index to mitigate possible
 race condition in

    find_or_create_by https://github.com/rails/rails/pull/31989 #rails6
  79. Person.pick(:name) Same as Person.pluck(:name).first https://github.com/rails/rails/pull/31941 #rails6

  80. Goodbye ‚ utf8 attribute no longer generated in form_tag by

    default https://github.com/rails/rails/pull/32125 #rails6
  81. Goodbye–✓ utf8 attribute no longer generated in form_tag by default

    https://github.com/rails/rails/pull/32125 #rails6
  82. update_attributes → update update_attributes! → update! https://github.com/rails/rails/pull/31998 #rails6

  83. Parallel Testing http://edgeguides.rubyonrails.org/testing.html#parallel-testing https://github.com/rails/rails/pull/31900 #rails6

  84. Expanded rails routes https://github.com/rails/rails/pull/32130 #rails6

  85. https://github.com/rails/rails/pull/32130 #rails6 Expanded rails routes $ rails routes --expanded --[

    Route 1 ]------------------------------------------------------------ Prefix | high_scores Verb | GET URI | /high_scores(.:format) Controller#Action | high_scores#index --[ Route 2 ]------------------------------------------------------------ Prefix | new_high_score Verb | GET URI | /high_scores/new(.:format) Controller#Action | high_scores#new --[ Route 3 ]------------------------------------------------------------ Prefix | blog Verb | URI | /blog Controller#Action | Blog::Engine [ Routes for Blog::Engine ] --[ Route 1 ]------------------------------------------------------------ Prefix | cart Verb | GET URI | /cart(.:format) Controller#Action | cart#show
  86. 5.2 6.0