“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:
Action Cable: Starring WebSockets
- The new framework integrates WebSockets with Rails. Real-time features are now allowed to be written in Ruby. Read more about WebSockets here.
- 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).
Active Record attributes API: User Defined Custom Types and More…
- 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.
- Much easier to deal with record work in batches, thanks to Relation#in_batches and reduce memory overloads.
- Active Record callbacks need not be accidentally halted sue to last false statement.You can now :abort explicitly.
- 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.
- 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.
- 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.
- Dirty Tracking: This attribute type provides the opportunity to alter dirty tracking performance.
API Applications: A Base for APIs
- 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.
- API can be used for serving custom and public facing applications.Configure applications with a limited set of middleware than normal.
- 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:
- Single test run using line number of test.
- Multiple tests pinpointing the tests line number.
- Test’s colored output.
- Test output deferred to the full test runs end, using -d option.
- Enhanced failure messages makes re-running failed tests easy.
- Test can be posted immediately using the fail fast -f option in case of failure. You do not need to wait for suite completion.
- Use -b option for exception backtrace completion output.
- Minitest integration allows options like -n for specific test by name amd -s for test seed data.
Other notable Rails 5.0 changes: Highlights
- New plugins and applications get a README.md at Markdown.
- Rails app can be restarted by touching tmp/restart.txt. The bin/rails restart task has been added for this purpose.
- Added bin/rails dev:cache to disable or enable development mode caching.
- Proxy Rake tasks can be conducted through bin/rails.
- 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.