New features in Rails 6: Multiple databases, parallel tests, Action Mailbox and more
With three beta versions released so far, Rails 6 is definitely on the horizon. It's about to bring changes extracted from or built by dev teams behind the framework's flagship products like Basecamp or GitHub. Let's see what new features its final release is bringing and consider if it's for the better or worse.
Rails 6: When is it going to be released?
The tentative timeline for the release of subsequent versions of Rails 6 was published by David Heinemeier Hansson in late December. Three beta versions are already there and the final one is expected to be live at RailsConf 2019, which is taking place between April 30 and May 2 in Minneapolis, USA.
Now, let's examine its new features piece by piece.
Feature 1: Action Mailbox
Extracted from Basecamp 3, Action Mailbox is the new framework that routes incoming emails to controller-like mailboxes in Rails. It allows Rails applications to better integrate with inbound emails.
Until recently, Rails used Action Mailer to receive emails from applications, but, as Hansson wrote some time ago, the whole way was "anemic", "poorly flushed out", "lacked cohesion with sending emails, and offered no help on integrating with popular inbound email processing platforms".
Already merged into Rails, Action Mailbox ships with ingresses from Amazon SES, Mailgun, Mandrill, Postmark and SendGrid.
This is why the new framework replaces Action Mailer in the receiving part.
Caution: Action Mailbox requires Active Job and Active Storage.
Feature 2: Action Text
Another extraction from Basecamp's code, Action Text is the second major new framework in Rails 6.
According to its creators, Action Text is going to make writing, editing and displaying text in a Rails app 'super easy' or 'take it to the next level'.
Action Text includes the Trix editor that handles:
- and adding links and lists to embedded images and galleries.
Any embedded content (images etc.) is automatically stored using Active Storage and associated with the included separate RichText model. Bearing that in mind, Active Storage is, again, required for this framework to work properly.
So, if this is what your application's future sounds like, Action Text is going to bring rich text content and editing opportunities to it.
Action Text was already working with Rails 5.2 apps, so devs who sought some out-of-the-box solutions already had the possibility to check it out.
Feature 3: Multiple databases support
Ever thought that your application could connect to and switch between multiple databases at the same time?
You might want to do this for scalability or performance reasons.
'A typical scenario is database configurations using a master-slave scheme, where the database is replicated across multiple servers, with the master node receiving all write operations, which are then propagated to slave servers. These, in turn, function as read-only to the application' - explains Michał Buszkiewicz, the Rails developer at Prograils.
He adds that previously, commonly used solutions for this and similar purposes included gems such as
ar-octopus - which has served as an inspiration to bring this sort of functionality into Rails core.
To meet this purpose, Rails 6 provides an API for multiple databases support, which is going to enable you do it without digging deep in Active Record.
Learn more about multiple db support from the original GitHub thread.
Feature 4: Parallel testing
Rails 6 adds parallel test to Rails applications by default.
Built by the GitHub team just like multiple db support, parallel testing is a functionality that may turn extremely useful when running hard tests for your application.
Taking advantage of multiple cores in your machine, parallel testing support is meant to speed up your testing suite. Each testing worker gets its own database and runs its own thread.
This feature is among the most popular ones in Rails 6. Read more about it in the official Rails GitHub repository.
Feature 5: Webpack as a default bundler
From now on,
webpacker is a gem providing integration with
webpack and JS package managers such as
'Since webpack is a de-facto standard in the front-end development community nowadays, it can make front-end developers with little to no Rails knowledge feel more at home' - says Buszkiewicz.
In case you want to learn more about Webpacker and how it's added to a legacy Rails app, read this post.
Feature 6: Zeitwerk, the new code loader
Attention gem authors! Rails 6 comes up with a brand new code loader for Ruby. Meet Zeitwerk, which is going to replace the classic Rails loader that has been around since 2004.
Zeitwerk was built with the intention of getting rid of all the gotchas of the classic loader, as well as eliminating all known use cases for
require_dependency. So if you, just like its author, are not necessarily a fan of
require, you will welcome Zeitwerk with arms wide open.
The new autoloader is also useful for gem or gem-like projects creators, since it allows any application to have its own independent loader, comprising own configuration, inflector and optional logger.
Fancy using gems? Check out the list of the most popular ones among our devs!
There's more to Rails 6...
Minor upgrades to Rails include: Proper Action Cable testing, Action Cable JS rewritten in ES6, protection against DNS rebinding attacks and per-environment credentials.
Remember that Rails 6 will require Ruby 2.5.0+ now.
To wrap up: What's coming with Rails 6?
David Heinemeier Hansson sees Rails 6 as 'really shaping up to be a major release'. Although the release date of the framework's new version is still unknown, most of its new features are already merged with Rails and can be tested.
'Rails is a mature project and it can be argued that it gets increasingly difficult to create new framework features that have the potential to be revolutionary' - claims Michał Buszkiewicz, noticing that some developers have raised concerns over the inclusion of new features such as Action Text, considering them "bloatware" and pointing out that they will likely increase application footprints.
These features are said to be turning the Rails team's attention away from areas where the framework could be improved with regard to performance or scalability (which, by the way are among the reasons behind Rails devs choosing Elixir/Phoenix as their next language or framework).
While some people have criticized the features to be shipped with Rails 6, others have praised the inclusions as keeping up with the spirit of Rails always aiming to provide opinionated, generic and standardized solutions to common problems.
'Time will tell which group is right. What's absolutely certain is the fact that the Rails team still looks for different ways to move the project forward' - concludes Buszkiewicz.
Have you already played with the new Rails features? Let us know how it was!
Attention Rails devs!
We are looking for a Rails developer to join our team in Poznań, Poland. So if you are familiar with the above new additions to the Rails univers are looking for a decent job, feel free to drop us a line.
Photo by Banter Snaps on Unsplash.com