Share
Embed
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.
Prem Sichanugrist
March 20, 2018
Transcript
86 slides
-
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 -
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 -
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 -
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 %> -
NEW Active Storage Q: Should I switch to Active Storage
from [___________]? #rails52 -
NEW Active Storage Q: Should I switch to Active Storage
from [___________]? A: Sure!* #rails52 -
NEW Active Storage Q: Should I use Active Storage for
my new project? #rails52 -
NEW Active Storage Q: Should I use Active Storage for
my new project? A: Yes. #rails52 -
#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" -
#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" -
#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" -
#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" -
#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" -
#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" -
#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" -
Rails 4 AES in CBC mode with HMAC using SHA1
#rails52 https://github.com/rails/rails/pull/28132 AEAD Encrypted Cookies -
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 -
#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 -
#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" /> -
Content-Security-Policy Control access to content from a user-agent #rails52 https://github.com/rails/rails/pull/31162
DSL for Configuring CSP Header -
#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 -
#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 -
#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 -
#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 -
#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 -
#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 -
New Threshold for Cache Compression Automatically compress value > 1kB
#rails52 https://github.com/rails/rails/pull/31147 -
Bootsnap in Default Gemfile Add gem "bootsnap" for current projects
#rails52 https://github.com/rails/rails/pull/29313 -
#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 -
.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 -
Goodbye ‚ utf8 attribute no longer generated in form_tag by
default https://github.com/rails/rails/pull/32125 #rails6 -
Goodbye–✓ utf8 attribute no longer generated in form_tag by default
https://github.com/rails/rails/pull/32125 #rails6 -
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