Rails 6.0 new framework defaults: what they do and how to safely uncomment them

What does this do?

How to safely uncomment?

What does this do?

  1. Rails sets two cookies, is_admin with a value of false and is_a_doofus with a value of true.
  2. Evildoers swap the encrypted/signed values of the two cookies.
  3. Rails reads those values on request and says “ahh, yes, these values haven’t been modified”.
  4. Rails thinks that you’re a non-doofus admin when in fact you are supposed to be a doofus non-admin.

How to safely uncomment?

# This option is not backwards compatible with earlier Rails versions.
# It's best enabled when your entire app is migrated and stable on 6.0.

What does this do?

How to safely uncomment?

Failure/Error: expect(response.content_type).to eq("text/html");expected: "text/html"
got: "text/html; charset=utf-8"
(compared using ==)
# ./spec/controllers/users_controller_spec.rb:10:in `block (4 levels) in <top (required)>'
  • expect(response.media_type).to eq("text/html"). The media_type method returns just the media type like content_type did previously.
  • expect(response.content_type).to include("text/html").
  • Consider refactoring your controller tests into system tests. Controller tests are deprecated.

What does this do?

class MyJob < ApplicationJob
before_enqueue { |job| throw(:abort) if job.arguments.first }
def perform; end
end
job1 = MyJob.perform_later(false)
job2 = MyJob.perform_later(true)

How to safely uncomment?

What does this do?

How to safely uncomment?

What does this do?

class User < ApplicationRecord
has_one_attached :avatar
end
sam = User.create.avatar.attach(some_image_file)
sam.avatar.attach(different_image_file)

How to safely uncomment?

What does this do?

class Message < ApplicationRecord
has_many_attached :uploads
end
files = get_array_of_files
message = Message.create(uploads: files)
files << get_another_file
message.update(uploads: files)
  1. Rails diffs the existing array with the new array. It uploads new files and ignores files that were already in the existing array.
  2. Rails doesn’t do any diffing. It purges all the existing files and uploads all the files in the new array.

How to safely uncomment?

What does this do?

How to safely uncomment?

The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob),
will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions.
If you send mail in the background, job workers need to have a copy of
MailDeliveryJob to ensure all delivery jobs are processed properly.
Make sure your entire app is migrated and stable on 6.0 before using this setting.

What does this do?

# In Rails 5.1
user = User.last
user.cache_key # "users/281-20191007212244313194"
user.touch
user.cache_key # "users/281-20191017003012868191"
# In Rails 5.2
user = User.last
user.cache_key # "users/281"
user.cache_version # "20191007212244313194"
user.touch
user.cache_key # "users/281"
user.cache_version # "20191017003012868191"
Rails.application.config.active_record.collection_cache_versioning = false
User.all.cache_key # "users/query-b03a3611aaa3ed0825f6b93870f69c0e-281-20191007212244313194"
Rails.application.config.active_record.collection_cache_versioning = true
User.all.cache_key # "users/query-b03a3611aaa3ed0825f6b93870f69c0e"

How to safely uncomment?

What does this do?

How to safely uncomment?

DEPRECATION WARNING: Initialization autoloaded the constant Foo.Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.
Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Foo, for example,
the expected changes won’t be reflected in that stale Class object.
These autoloaded constants have been unloaded.
# app/foo.rbclass Foo
def self.bar?
true
end
end
# config/initializers/baz.rb
BAZ = Foo
# config/initializers/baz.rbclass Foo
def self.bar?
true
end
end
BAZ = Foo
# config/initializers/baz.rbrequire Rails.root.join('lib', 'foo')
BAZ = Foo

Edit (3/30/2021)

Unable to load application: Zeitwerk::NameError: expected file /foo/bar.rb to define constant Foo::Bar, but didn't
# /foo/bar.rb
class Bar
# ...
end
# /foo/bar.rb
class Foo::Bar
# ...
end
Unable to load application: Zeitwerk::NameError: expected file /csv.rb to define constant Csv, but didn't
# /csv.rb
class CSV
# ...
end
# config/initializers/inflections.rb
# These inflection rules are supported but not enabled by default:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'CSV'
end

--

--

--

Seeking staff engineer position

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Fix Composer Memory Limit on Vagrant ?

Writing RESTful APIs in Go, 3 years later

Implementation methods for events and transactions tracking in Google Analytics

TPM (Technical Program Manager)

New Board Game: Dice Power Transfer Backgammon

Let’s Play Game of Life with Python

The Basics of Cost Saving With Reserved AWS Capacity

How to Choose The Best Business Automation Software: Three Practical Tips

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Lily Reile

Lily Reile

Seeking staff engineer position

More from Medium

Ruby on Rails Project: Devhub

When and Why use React with Ruby on Rails?

How We Solved Sidekiq Memory Issue In Rails Application

All the Code I Didn’t Write