What’s new in Rails 5.1

For each one of us who’s been waiting for the release of the all-new and neat and clean version of Rails 5.1, the wait is over. The new version of Rails 5.1 easily accepts the SPA (Single Page Application) and it also represents a genuine upgradation in terms of performance and structure of Rails, one of the most popular frameworks. A multitude of improvements such as system testing, encryption and managing JavaScript dependencies are supported by Rails 5.1

Some Rails 5.1 features are listed below:

Ruby Version

It requires Ruby 2.3.1 or greater version of ruby.

No More RAKE Commands

When we want to run a migration in Rails 4 we need to type rake db:migrate, but in Rails 5.1
this will become rails db:migrate. In Rails 5.1 all the current rake commands will be accessible via the rails command.We can now restart all of our apps with the command rake restart.

App Server

In Rails 5.1 app, by default Puma server is present in Gemfile.

Rails 5.1 App Server

Yarn Support

Yarn is like a Bundler for managing JavaScript dependencies from NPM.with this we can easily use libraries like React, VueJS or any other library from NPM world. It is integrated with the asset pipeline so that all dependencies will work seamlessly with the Rails 5.1 app.

On Debian or Ubuntu Linux, to install Yarn via Debian package repository follow the below command:
Rails5.1 Yarn Support

Webpacker Support

Webpack can used to compile Javascript using webpacker gem. It is used to manage modules and dependencies.If we are in the single page applications,easily we can setup React, Angular, and Vue.js. To start a Rails/React project we can run the below command:

Rails 5.1 Webpacker Support

For an existing project, first we need to add the webpacker gem in Gemfile,then run the above command. In the same way we create the app for Angular and Vue.js.For more information on webpacker refer this link https://github.com/rails/webpacker.

New form_with helper

A new form_with helper has been added in Rails 5.1 which combines form_for and form_tag methods.

Examples:
Rails5.1 Newform

Direct and Resolved Routes

These two new methods direct and resolved has been added to the Routing DSL.
The direct method allows creation of custom URL helpers.
Example:

Direct Resolve Route

The resolve method allows us to customize polymorphic mapping of models.
Direct Resolve Route 2

This will generate the singular URL /product instead of the usual /products/:id.

Parameterized Mailers

Now in mailers we can define before action by passing in parameters to the method. This parameters will be used for all methods in a mailer class, in order to share instance variables, headers and other common setup.
Example:
Parameterized Mailers

New Tag helper

The ActionView tag helper has been changed to provide a cleaner and readable syntax:
New Tag Helper

System tests

The best solution for system tests on Ruby was using Capybara. Using it currently involves setting up Capybara in our project, along with a strategy for cleaning our database with tools like database_cleaner and launchy gem to help us to debug when an error happens.

Looking to get your app developed? RailsCarma can help! Check out our portfolio to understand how we are helping to change the shape of software industry by providing Ruby on Rails Developer. Get in touch with us now!

Save

Save