It’s here! Rails 6 seems to be much kinder, after the breaking changes of Rails 5. But it still packs a punch. It focuses a lot on speed and scalability. There’s also some nifty features borrowed from Basecamp.
Here’s my favorite Rails 6 features.
Active Record: Connection Switching to Support Multiple Databases
This is crazy! When I read about it I was like “finally!”. With connection switching your Active Record model can connect to multiple databases. This allows for a primary “write” database and a replica “read” database.
How great is that! To make this happen, just add the required configuration to your database.yml.
Courtesy: Guy Maliar’s, “ What’s coming to Rails 6.0? ”
Action Mailbox: Receive Emails Within A Rails Application
I’m sure this is a feature that will be spoken about up until Rails 7 is out! It certainly is one of the most exciting.
Action Mailbox routes incoming emails to a controller like interface. There’s support for SendGrid, Mailgun, Mandrill and more right out of the box.
All incoming emails are turned into InboundEmail
records that store life-tracking information and also the original email as via ActiveStorage.
InboundEmail records will automatically be removed after 30 days. The idea being that all required information is extracted into other domain models by that time. And also it’s all about that data privacy, it’s 2019 mate!
Here’s a small snippet that shows how you can listen to incoming emails from a user and add it as a comment from them.
Action Text: Handling Rich Text Content
Action Text is a wonderful port of Trix editor by Basecamp right onto Rails 6.
With Action Text, adding a text editor is super easy. And since it’s Rails, it includes conventions for forms, Active Record and Active Storage.
You will first need to run rails action_text:install
to add the Yarn package and copy over the necessary migration. Also, you need to set up Active Storage for embedded images and other attachments.
Let’s look at some code!
Add has_rich_text
to the preferred attribute on your ActiveRecord model.
Now let’s look at the form helper to support Action Text.
How nifty is that rich_text_area
function? It expands into a WYSIWYG HTML editor!
Now to display a sanitized version of the saved text, just do
So simple!
There’s a bunch of new features that Rails 6 introduces. Read about all of them on the official Release Notes page. And write to me about your favorite feature, just tweet to me at @imswaathik .
Subscribe to our newsletter
Get the latest updates from our team delivered directly to your inbox.
Related Posts
10 Gems in Ruby that you will love
Let's go back to basics with Ruby on Rails and see some of the Gems that we use everyday at skcript. #StartWithSkcript
#100DaysOfCommits
Our CTO, Swaathi, talks about our commitment to the #100DaysOfCommit challenge. Join us.
18 Python packages you should be using right now
Let us look at some python packages that will get you started on your machine learning path #StartWithSkcript