googleads
Rails 6.0 - The Top 3 great features | Ruby on Rails
preloder
Ruby Ruby on Rails Technical Web Development

Rails 6.0 Features – The Top 3 Great Features of the latest rails version

Rails is a web application development framework that is written in a language called ‘Ruby’. This language allows you to write shorter codes without compromising its functionality. While accomplishing more than many other languages and frameworks, now the release of new version Rails 6.0.0 with more useful features is trending among techies. 

So, this blog unveils the main features of latest rails 6.0 version.

Upgrading Rails App to 6.0

Action text

Action Mailbox

Multiple Databases with Active Record

Upgrading Rails 5.2 to 6.0

Rails 6 requires Ruby 2.5.0 or newer to update. We need to update the ruby and rails version respectively, and then you update in “gemfile”. Now, run this command. 

You can use this task to update the rails app

You may need to change many things manually. 

They are Config.load_defaults value in “config/application.rb”.

Then, add “webpacker” gem into our application.

Run the following command

The above command creates a separate folder for javascript. We need to migrate all our existing javascript to it.

If you were previously loading any of the actioncable, activestorage, or rails-ujs, it will now load packages through npm/yarn.

Webpacker, besides being the default JavaScript compiler for Rails 6, it does not get activated by default when upgrading. So, when using Webpacker, include it in your Gemfile and then install it.

Once all npm package is moved to @rails scope, you got to update the names of the following dependencies. 

If this looks like a long process for you, just create the new rails 6.0 app and migrate your code. And you can use yarn add “any lib” to do this.

Here, let us consider an example for a clearer understanding of the features. Creating an app for an email campaign would be a great concept. Using action text, we are going to draft a newsletter and send it to the subscriber. The subscriber can able to reply through the email and that is going to be captured with help of action mailbox and add to the comments table. Here, a separate database is created for comments to implement the Multiple Databases with Active Record feature.

So now you can create the new application and models with the following commands. 

Make DB config and migrate the app.

Now add action text field “content” in the newsletter model. 

Action text

Action Text brings rich text content and editing to Rails. It includes the Trix editor which handles all of your actions like adding image, text, link and others to the content. Following is the code to install.

It installs active storage if that’s not present in your application.

You need to add the above line to your model to add rich text field.

Place the above code in the ‘view’ section.

Furthermore, permit the params in controller

To change the design, you need to remove the default one.

you need to remove the app/assets/stylesheets/actiontext.scss linker and base your stylings on the contents of that file. Get additional information here

Here, the email configuration to send an email for the subscriber is done using “mailgun”, you can do with your preferred mail service. 

Now, proceeding to capture the reply text from email by the subscriber, add the “reply_to” field when sending an email. Add the newsletter id to track user reply to which the newsletter goes. 

Action Mailbox

Action Mailbox routes incoming emails to controller-like mailboxes for processing in Rails. It ships with ingresses for Mailgun, Mandrill, Postmark, and SendGrid. You can also handle inbound mails directly via the built-in Exim, Postfix, and Qmail ingresses.

This will also generate active storage migration and action mailbox. And create file application_mailbox.rb in mailboxes.

Here, you can define your routes, and then create the mailbox for replies likewise the code given below. 

This code creates the replies mailbox for the further use. There, you can find a process method and get access to the “mail” object.  

You can access all the mail parsing methods of mail gem, because it is built on top of this. 

Above is the mailbox class, where we are processing the inbound mail. To capture your mail, configure your domain in MATCHER.  

For testing in local

Start your rails server, enter the URL given below. Here you will get a form to test your mailbox.  

If you need to test with your actual mail, you need to set up server or ngrok(local). Then, configure routes in “mailgun”.  

Add comments table in separate database by using the Multiple Databases with Active Record feature in rails 6.0

Multiple Databases with Active Record

This feature becomes almost inevitable when you are scaling up your application on a database level. The latest version aids you by supporting multiple databases to store your data. With the multiple database structure, you do not need to rely on one single database which eventually enhances the speed when retrieving data from the database.

Firstly, you need to add the new database config in database.yml file. 

Here, add multiple databases for the development. You need to use replica: true for creating the database replication. 

The “migrations_paths” is used to fix the location of the migration files for a particular database. 

To create the model or migration on a particular database

The following commands allow you to create a model and migration on a particular database respectively.

To migrate specific database

Now, comment model is created on database primary2 by using the above command.  Before configuring in your model, you can’t access the active record.

So, the above picture shows that the comments database is not connected via model.

For connecting with active record, add the following to your model

Once the model is connected, now you can check in rails console which will return the record as shown below. 

You can refer to my Github repo to get the complete code. Do share your thoughts about the most interesting feature that you felt in rails 6 below in the comments.

Happy coding!

Hire best Ruby on rails developers for your web development projects easily with Agira technologies. We provide you with dedicated experts who have mastered the latest technologies. Endure the fullest of outsourcing tech experts for your company. Get in touch with our experts to hire freelance python developers, offshore python developers and python web developers who can cater to your company’s requirement.

Python web development

Read more blogs related to Ruby on rails and other latest tech news. Such as Active Storage In Rails 5.2 With Real Time Example and How to Learn Ruby on Rails from Scratch – Beginners Guide!

Like What You're Reading ?

 

The following two tabs change content below.

Guru Moorthy

An active Full Stack Blockchain developer having 3+ years of experience in Blockchain. With great passion, he immensely adapted himself in complete life cycle of Blockchain & Crypto development. And, This rising Blockchain enthusiast have forked and modified 12 out of top 20 Crypto coins and aiming to explore all use cases of Blockchain.

Leave a Reply

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

[contact-form-7 id="120788" title="Web Page Form"]

Schedule Your Call