New features in Rails 6: Multiple databases, parallel tests, Action Mailbox and more
After several working versions released previously, Rails 6.0 is finally out, bringing 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 for the Ruby on Rails ecosystem.
Rails 6 finally released
The tentative timeline for the release of subsequent versions of Ruby on Rails 6.0 was published by David Heinemeier Hansson in late December 2018. Three beta versions were released until the end of Spring and the final one was expected to be live at RailsConf 2019 between April 30 and May 2 in Minneapolis, USA. But it wasn't until August that the final version of Rails 6.0 was released after two years and thousands of commits.
In this article, we will examine its new features piece by piece. But if you want to go straight to the practical side of things and learn how to update your app from Rails 5.2 to Rails 6.0, head over here.
Feature 1: Action Mailbox
Extracted from Basecamp 3, Action Mailbox is the new framework that routes incoming emails to controller-like mailboxes in Ruby on Rails. It allows Rails applications to better integrate with inbound emails.
Until recently, RoR 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:
- formatting,
- quotes,
- 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, webpack
is going to be a default JavaScript bundler for Rails through the webpacker
gem, replacing the previously-default Rails Asset Pipeline and providing for better interoperability with modern JavaScript libraries and coding standards.
In short, webpacker
is a gem providing integration with webpack
and JS package managers such as yarn
.
'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.0 as 'really shaping up to be a major release'. Although its final release took place only in late August, most of its new features had been already merged with ROR and could have been 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 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 in the comments section!
Is Ruby on Rails a good solution for your business?
Having been around since 2004, Ruby on Rails to this day powers many popular websites including Basecamp, Airbnb, Shopify and more. Besides that, features such as the syntax of Ruby language, vast availability od readymade solutions to standard problems (called gems) contributed by the Rails community make it a proper solution for startups planning to release their minimum viable products. If you need more details on how Ruby on Rails development can help you build your MVP, read this article.
All this is backed up with real life evidence and our experience. There are multiple projects in the Prograils portfolio that started as Ruby on Rails MVPs and have been refined and developed up to the enterprise level over the years. Thinking about building your web application with Ruby on Rails 6.0? Tell us about your idea.
We're hiring!
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 universe and are looking for a decent job, feel free to drop us a line.
If you would like to learn more about our recruitment process for Rails devs, read this article.
Photo by Banter Snaps on Unsplash.com