Ruby Inside
Published in

Ruby Inside

What’s coming to Rails 6.0?

Rails 6.0 will be released soon and it’s packed with many features that both smaller and bigger applications will benefit from, as it feels like many improvements around speed and scalability were introduced in Rails 6.

I’ve read through the CHANGELOGs of all Rails parts (ActiveRecord, ActionPack, ActiveSupport, etc.) and picked some of the features that I found the most interesting.

Two new additions to the Rails family are Action Mailbox and Action Text that come straight out of Basecamp.

Active Record

Connection switching support has been on my list for a long time, I’ve used the Octopus gem a few times before as well, but it always felt a little bit clunky in my opinion.

Eileen M. Uchitelle has extracted out of Github’s codebase and into Rails’ this amazing feature, a native solution to switch database connections for specific models and/or specific queries.

The code is available as part of the pull request,, it’s documented amazingly and very easy to follow through.

Slow queries in jobs can be read from a replica using a simple API

And the database.yml file is simply a little bit longer

Gannon McGibbon later added some more amazing code supporting hash and url configs in database hash of ActiveRecord::Base.connected_to which open up these possibilities

Just as the name suggests pick can pluck single-values

A while back, DHH have started YouTube series called On Writing Software Well which later became part of the Getting Better YouTube page, on one of the videos he shows his technique for addressing the issues with find_or_create_by and the alternative create_or_find_by which relies on a database unique constraint. The code itself is fairly intuitive and is taken directly from the Rails sourcecode.

There are several drawbacks to this solution which are stated and I suggest reading them before using this solution.

For applications that don’t use sequential IDs this one is golden. When using UUIDs as default column identifier, first and last methods no longer make sense. Now we will be able to set the order of the records with a single line of configuration.

Action Mailbox

Action Mailbox is introduced in the sixth version of Ruby on Rails, I’m sure many posts will be written about it in the near future and it’s pretty exciting. Action Mailbox provides a set of tools that will allow applications to better integrate with inbound emails flows.

The basics are covered at Action Mailbox Basics Rails Guide but a few cool ideas would be conversations that happen automatically in both a platform and email and are interchangeable, think about Github comments from emails, help desk emails that turn into tickets or even GDPR delete requests.

Example mailbox for adding comments to a Post by email

The documentation to set up Action Mailbox is available at, it covers the required configuration of Action Mailbox available providers.

Pay attention that Action Mailbox requires Active Job and Active Storage as part of it’s and a database table. Most of the class documentation is also available at ActionMailbox::Base class documentation, ActionMailbox::InboundEmail class documentation and working with a parsed email is done by using the Mail gem.

Action Text

Action Text is an implementation of the new Trix editor by Basecamp bundled into ActiveRecord models. It exposes a has_rich_text method that we can apply to models and Action Text will take care of the rest. Action Text requires ActiveStorage and some database tables to persist it’s metadata, so be aware that you’d want to switch to an ActiveStorage provider that does not persist to disk if you’re working on applications that require more than one server.

The documentation is available at the Rails Guides and it’s pretty self-explanatory.

Action Pack

Host Authorization is a new middleware that guards against DNS rebinding attacks by explicitly permitting the hosts a request can be sent to. More information about the attack itself is available in this Medium post and in Daniel Miessler’s DNS Rebinding attack explained.

By default it’s set for all Rails 6 applications and allows in development the following hosts“”),“::/0”), “localhost”] it supports arrays of RegExp, Proc, IPAddr and String or a single String in the configuration. What this means is that with Rails 6, we will need to explicitly set our domains in the environments configuration files.

More information is available at the HostAuthoriation code and HostAuthorization tests.

Rails can now thwart attacks that attempt to copy signed/encrypted value of a cookie and use it as the value of another cookie.

It does so by stashing the cookie-name in the purpose field which is then signed/encrypted along with the cookie value. Then, on a server-side read, we verify the cookie-names and discard any attacked cookies.

Enable action_dispatch.use_cookies_with_metadata to use this feature, which writes cookies with the new purpose and expiry metadata embedded.

It’s possible to pass parameters to the underlying GET request in a follow_redirect! by adding an additional arguments to the method.

Action View

Aaron Patterson is on an ever-long performance optimization quest and his latest addition is allocations. Rails 6 will report on allocations made in views, which will allow developers be aware of how much time is spent in allocating and garbage collecting objects in the process’ memory.

Active Job

Rails has a very extensive instrumentation hooks built into Active Support and it spans across the entire framework.

It allows subscribing on specific events that happen throughout the lifecycle of requests, SQL queries and jobs and report them for example to a Prometheus instance.

With the addition of enqueue_retry.active_job , retry_stopped.active_job and discard.active_job it is easier to instrument based on jobs’ status.

It’s now possible to retry on multiple exceptions

Active Model

This still defaults to an attribute named 'password', causing no breaking change. There is a new method #authenticate_XXX where XXX is the configured attribute name, making the existing #authenticate now an alias for this when the attribute is the default 'password'.

Active Storage

In rails 5.2 files were persisted immediately when assigned

Rather when was called, the behavior now is as expected

ImageProcessing support some better macros such as :resize_to_fit, :resize_to_fill and also has built in libvips which is in an alternative to ImageMagick.

The change is also easily configurable using the usual Rails configuration

Action Cable

This is a pretty cool addition, it lets us test action cable interactions more easily.

Taken from action-cable-testing gem on Github

I personally prefer ES2015 javascript to Coffeescript so I think it’s great.

Action Mailer

DeliveryJob and Parameterized::DeliveryJob are deprecated in favor of MailDeliveryJob it is used for sending emails outside of the request-response cycle.

Action Support

Parallel testing was a little bit hard up until Rails 6 especially in CI systems when you needed isolation between processes and interference with the database. I’ve written some weird database.yml s that rely on an environment variable that creates multiple databases in each of the CI build. Starting Rails 6 that would no longer be necessary as it is possible to just specify in Minitest

or through environment variable PARALLEL_WORKERS and it’ll create the database with a numbered suffix.

More information is available in Bogdan’s What Is New In Rails 6.0

Tracing constant autoloads is pretty easy now if you’re having trouble with autoloading constants on file changes.

Create an initializer called autoload_trace.rb and add the following code


Zeitwerk is a new code loader for Ruby. It is efficient, thread-safe, and matches Ruby semantics for constants.

Given a conventional file structure, Zeitwerk loads your project’s classes and modules on demand meaning you don’t need to write require calls for your own files.

To enable it in Rails 6, simply set

config.autoloader = :zeitwerk

in your environment files.

More info here: and here:

Thanks to Sean Handley for pointing it out and writing this content about Zeitwerk!


In order to upgrade to Rails 6 we must upgrade to Ruby 2.5+, quite obvious.



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
Guy Maliar

Co-founder @ Gluework | Software Engineer | Google Developer Expert