• Ruby on Rails
  • < 1

New Features and Major Changes in Rails 5

  • POSTED ON
  • January 21, 2016
  • POSTED BY
  • Aayan Arif
  • POSTED ON January 21, 2016
  • POSTED BY Aayan Arif

ActionCable is a library that will ship with Ruby on Rails 5. It integrates WebSockets with the rest of your Rails application that facilitates you to push live updates to your client. This will make it easy to add real-time features to a Ruby on Rails application. This library runs in a separate process from the main application server and needs a multi-threaded....

ActionCable

ActionCable is a library that will ship with Ruby on Rails 5. It integrates WebSockets with the rest of your Rails application that facilitates you to push live updates to your client. This will make it easy to add real-time features to a Ruby on Rails application.

This library runs in a separate process from the main application server and needs a multi-threaded web server like Puma or Thin. Therefore, Puma is added as a default web server in Ruby on Rails 5.

ApplicationRecord

In earlier versions of Ruby on Rails, all models were inherited from ActiveRecord::Base. But now starting from Ruby on Rails 5, all models will be inherited from ApplicationRecord. Its class will be used for customization and extensions needed for an application, instead of monkeypatching ActiveRecord::Base.

By monkeypatching ActiveRecord::Base, the extra functionality is added to all models. On the other hand, if you want to include an extra functionality to ApplicationRecord then it will be localized to the models inheriting from ApplicationRecord.

Rails API

Rails 5 allows you to generate API-only applications. The rails-api gem has been merged to rails gem that allows you to generate API-only application and strip out all extra middleware.

ActiveRecord::Base#has_secure_token

Rails 5 have introduced another very useful feature for generating a random token. If you need a random token in your model, you can use ActiveRecord::Base#has_secure_token which handles this process.

Attributes API

Your models will get a new attribute class method in Rails 5 that allows you to easily define a relationship between the model and a non-Active Record type. No more misusing is serialized!

ActiveRecord::Base#where.or

With Rails 5, ActiveRecord::Base#where.or has been introduced. You can now perform SQL “or” operation with Rails way as:

Post.where('id = 1').or(Post.where('id = 2'))

ABOUT THE AUTHOR

Aayan Arif

Content Strategist at vteams - Aayan has over 8 years of experience of working with multiple industries.

0 Comments

Leave a Reply

More Related Article
We provide tips and advice on delivering excellent customer service, engaging your customers, and building a customer-centric business.