Ruby On Rails 6 Features: What’s New and Why It Matters

Rails 6 finally released!

Rails 6 latest version rc2 has now released on July 22, 2019. This may be the best-exercised RC (release candidate) in Rails history.

Let’s see what are the new Ruby On Rails 6 features are added in the final release of 6.0.0.rc1

  1. Action Mailbox
  2. Action Text
  3. Parallel Testing
  4. Action Cable Testing
  5. Webpack
  6. Multiple databases support

1) Action Mailbox

In Rails 5, we were using ActionMailer to manage mails in the application.
Action Mailbox is extracted from Basecamp, which gives you the way for incoming emails to the mailboxes as a controller for processing in the rails application. Also, it has access to integrate Mailgun, Postmark and SendGrid. Along with that, you can implement and work on handling inbound mails directly via the built-in access to Exim, Postfix and Qmail.
The inbound emails are considered as ‘InBoundEmail’ records using Active Record and tracking of its lifecycle, store original email on cloud storage via Active Storage. Also, it is responsible for data handling with on-by-default destruction process. By default, an ‘InBoundEmail’ that has been successfully processed will be destroyed after 30 days.
NOTE.: Action Mailbox requires Active Job and Active Storage.

2) Action Text

This is another extraction from Basecamp. According to Trix, this is a rich text content and editor for everyday writing that added to Rails 6.
This editor handles everything from formatting, quotes, lists and embedded images and galleries. Any embedded images or attachments are automatically stored using
Active Storage and associated with the RichText model
Action Text already included in Rails 5.2, so many developers might have used it and also aware of the challenges if they have faced. This will give you opportunities to edit and bring rich text content.
Trix Editor:-
Why was Trix editor added to Rails 6?
Most WYSIWYG editors use HTML’s content editable and execCommand that are designed by the Microsoft support team for Internet Explorer 5.5. And based on reverse-engineering, those things copied from other browsers, so during implementation, each browser has its own issues and that leads to inconsistency.
But, Trix uses HTML’s content editable as an I/O device and overcome this inconsistency.
NOTE.: Action Text requires Active Storage.

3) Parallel Testing

Rails 6 added parallel testing by default. This feature is built by Github. Parallel testing allows you to run each test parallelly. It reduces the time to execute the test suite.
The machine has multiple cores and can create workers too. Using Rails 6, we create workers and based on each worker, Rails create a test-database. So, the test will have these numbers of the database to run the test suite. We can create workers in two ways:
By adding parallelize(workers: 2) to your test_helper.rb
By adding PARALLEL_WORKERS=2 rails test
Example: If you have created 2 workers then the test will create test-database-0 and test-database-1.
If you love to run the test using threads and JRuby, then it has additional property as a thread. To add this, you need to add `parallelize (workers: :number_of_processors, with: :threads)` to your test_helper.rb. This threading parallelization is supported by Minitest’s Parallel:: Executor.

4) Action Cable Testing

This is a small feature added in Rails 6. In this, Rails allows testing your action cable functionality at any level. The levels are:
  • Connections
  • Channels
  • Broadcasts
We do a connection test to check the connection’s identifiers are assigned properly or are there any improper connection. Channel tests only assert the channel subscribes to the particular stream or not. The broadcast test is to check whether the message has been broadcasted inside other components.

5) Webpack

Webpack bundler has been added as default in Rails 6. Previously Rails uses Assets Pipeline to built JS and CSS. But now, using webpacker gem, all StyleSheets, images and JS libraries wrap into a single bundle with a single access point.
Webpack working
Some people already using webpack bundling with rails 5.1+ version. But, in that version, we need to configure it using the command ‘rails new app –webpack’. Now, it is by default into the rails app.
Webpack is a static module bundler for modern js applications. Webpack helps during connecting Rails app with UI frameworks like ReactJs, AngularJs, VueJs, etc. Also, using this we can easily build hot reloading into Rails 6 application.
The webpacker gem provides integration with webpack and npm/yarn. Npm and yarn both famous for fast, reliable, and secure dependency management.

6) 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.

Leave a Reply

Your email address will not be published. Required fields are marked *