4 Mins Read  July 22, 2016  Snehith Kumbla

Rails 5: New Features and Improvements

Releasing a major version is like moving to a new place. This is what’s going to happen to Rails 5 too. Rails 5 is the best release that Rails is gonna have. It is gonna be more welcoming, especially to newcomers.” – Claudio Baccigalipo, member of the Rails issue team.

The inseparable Ruby companion Rails recently had another new version release. According to the software quality company TIOBE July 2016 index, Ruby stands 11th in this list of widely used and most popular languages. Check the entire survey out here. Rails 5.0 saw its version release on June 30, 2016. This process spread over 6 months with four beta versions and two release candidates. Ruby 2.2.2 is the minimum requirement for using Rails 5.0. As a precautionary measure, upgrade to Rails 4.2 and check if the application still runs, before moving on to Rails 5.0. If you are just starting with Rails, check this link out .Let us now look at the main changes in Rails 5.0:

ruby-on-rails 5

Action Cable: Starring WebSockets

  1. The new framework integrates WebSockets with Rails. Real-time features are now allowed to be written in Ruby. Read more about WebSockets here.
  2. The features can be written in the same form and style like the rest of your Rails application, while still scalable and performant (a full-stack offer).
  3. A server-side Ruby framework and client-side JavaScript framework ensures easy use of chat, notifications and other features.

Active Record attributes API: User Defined Custom Types and More…

  1. An attribute with a type on a model is defined.The existing attributes will be overridden, if required. This permits control on value conversion to and from SQL, when allotted to a model.
  2. Much easier to deal with record work in batches, thanks to Relation#in_batches and reduce memory overloads.
  3. Active Record callbacks need not be accidentally halted sue to last false statement.You can now :abort explicitly.
  4. You don’t have to depend on implementation details or monkey patching, for permitting usage of domain objects in ActiveRecord::Base. This allows type detection to be overridden by Active Record. Attributes no longer need database column backing.
  5. Creating Custom Types: Custom types can be user defined. The only condition: they must respond to value type defined methods. Useful in custom conversation, for eg, Money data.
  6. Querying: When ActiveRecord::Base is called, model class defined type is used for value to SQL conversion, calling serialize on your type object. While performing SQL queries, objects thus get the ability to specify and convert values.
  7. Dirty Tracking: This attribute type provides the opportunity to alter dirty tracking performance.

API Applications: A Base for APIs

  1. Slimmed down API applications can be used to create and serve APIs similar to GitHub,Twitter, etc. ApplicationRecord is now a default parent class of all generators created models.
  2. API can be used for serving custom and public facing applications.Configure applications with a limited set of middleware than normal.
  3. Rails 5.0 is apt for client-side native or JavaScript applications. These applications just require backend to speak JSON. The new api mode makes this even more clear.
  4. ActionController: Make ApplicationControl inherit from ActionController: API instead of ActionController. As with middleware, leave out any Action controller modules that provide functionalities mainly used by browser applications.

A base for APIs: Generators are to be configured to skip view generation, assets and helpers even as a new resource is generated. The application provides a base for APIs. The configuration can be done to pull in functionality, as is found suitable to the application’s needs.

Test Runner: New and Improved

Running test capabilities on Rails is further enhanced with a new test runner. Just type bin/rails test to use this test runner.Test Runner is inspired from maxitest, minitest-reporters, RSpec, apart from others.Notable Test Runner advancements:

  1. Single test run using line number of test.
  2. Multiple tests pinpointing the tests line number.
  3. Test’s colored output.
  4. Test output deferred to the full test runs end, using -d option.
  5. Enhanced failure messages makes re-running failed tests easy.
  6. Test can be posted immediately using the fail fast -f option in case of failure. You do not need to wait for suite completion.
  7. Use -b option for exception backtrace completion output.
  8. Minitest integration allows options like -n for specific test by name amd -s for test seed data.

Other notable Rails 5.0 changes: Highlights

  1. New plugins and applications get a README.md at Markdown.
  2. Rails app can be restarted by touching tmp/restart.txt. The bin/rails restart task has been added for this purpose.
  3. Added bin/rails dev:cache to disable or enable development mode caching.
  4. Proxy Rake tasks can be conducted through bin/rails.
  5. New applications can be generated using the evented file system monitor enabled on Mac OS X and Linux.

Rails 5 Summary

There is more to the Rails 5 release. To rewind, a Rails app can be built in API mode in the back end, making it easy to build the back end. Meanwhile, other frameworks like React can help you in the front end.

The new Action Cable feature enables developers to go out of the box, write apps with real time updates, especially useful in building chat apps. Get a sneak at other Rails features in this link.Also see how JSON API works with Rails 5 in this video. For more on all things technology, keep visiting our blog.

Recommended Content

Go Back to Main Page