Back in April, we published a video highlighting anticipated features of Rails 6.0! Rails 6 has published a ton of new features, and with the regular releases of the beta versions, developers had already access to the upcoming features, and rails developers reported the updated version looks solid. Let’s have a look at the key Rails features that you would like to use moving forward.
Action Mailbox is the new framework that is extracted straight from the Basecamp 3. Action Mailbox let you integrate Rails applications with inbound emails. Till the period Rails was accessing Action Mailer to receive emails from the applications. Incoming email is stored in a database table whereas ActiveJob is utilized to tie another automaton together.
When a user replies to the email, the app notifies about a comment. The user could make it possible to reply to that email, and your app could process that email and in turn into a comment automatically. Action cable let you test your functionality at any level: channels, connections, and broadcasts.
Here’s a small example taken from Taptol to understand how to use Action Mailbox:
COMMENTS_REGEX = /^comment\+(.+)@example\.com/i # app/mailboxes/application_mailbox.rb class ApplicationMailbox < ActionMailbox::Base routing COMMENTS_REGEX => :comments end # app/mailboxes/comments_mailbox.rb class CommentsMailbox < ApplicationMailbox def process user = User.find_by(email: mail.from) post_uuid = COMMENTS_REGEX.match(mail.to) post = Post.find_by(uuid: post_uuid) post.comments.create(user: user, content: mail.body) end end
Action Text is another extraction from Basecamp’s code, and it is the second new major framework in Rails 6. Action text includes Trix to take care of formatting links, embedded images, galleries and more. To enable Action Text just add a line of code
has_rich_text: column_name, and then after use
‘rich_text_area’ field to view.
It’s a new code loader for Ruby that gives conventional file structure to your project’s classes as well as modules on demand. That means you are not required to write calls for your files. Zeitwerk uses file names to ease the loader in more efficient way. Zeitwerk matches Ruby’s semantics for constants. To use it in Rails 6 set
config.autoloader = :zeitwerk
In the Rails applications, parallel testing is added by default. Parallelize method is added to Rails 6 to parallelize the test suite with forked processes. GitHub team has built it similar to the multiple DB support that has turned to be enormously useful while running hard tests for your application.
Run the test suite on multiple threads; parallel testing enables faster test suite run times along with efficiency. Leveraging the benefits of parallel testing support to speed up your testing suite. This feature is one of the most popular features on Rails 6; you can read more about it here.
To enable parallelize processes test add
Alternatively, we can also replace it with your previously used commands for running tests. For example,
bin/rails test OR bin/RSpec spec can now be replaced by
PARALLEL_WORKERS=15 rails test OR PARALLEL_WORKERS=15 RSpec spec.
Webpack as a Default Bundler
In a simple term, webpacker is a gem providing integration with JS package managers and webpack such as yarn. In case if you want to learn more about Webpacker, please, go through this article, how to add Webpacker to a legacy Rails application.
Without a serious security enhancement, no update is ever completed. Rails 6 has given special importance to the security in addition to the support for Host Authorization. Host Authorization is a new middleware that secures against DNS rebinding attacks by clearly permitting the hosts request. That means you can define the hosts that can access your applications.
The security upgrade is meant to prevent the attacks the attempt to copy the signed/encrypted value of a cookie and make use of it as the value of another cookie. It does by stashing the cookie on the server-side read and discard any attacked cookies. To use this feature, enable
action_dispatch.use_cookies_with_metadata that writes cookies with the new purpose and expiry metadata embedded.
There's more to Rails 6
per-environment credentials, and protection against DNS rebinding attacks. Keep into consideration; Rails 6 requires 2.5+ version.
At Bacancy Technology, we have a pool of skilled developers, who have in-depth knowledge and extensive experience in Ruby on Rails. Hire Ruby on Rails developer from us to leverage our top-of-the-line expertise to upgrade to the updated rails version. If you would like to know more about our Rails expertise, get in touch with us at [email protected]