Coming soon after RailsConf 2016 in Kansas City, Mo., Rails 5 is alive!
OK, but what’s really new in Rails 5? And what about monitoring Rails 5 applications?
Before we get into that, the first thing you probably need to know is that the minimum version of Ruby supported by Rails 5 is 2.2.2. So make sure you’re on Ruby 2.2.2+ before you upgrade or start a new Rails 5 project. (For additional details on migrating from Rails 4 to Rails 5, check out the complete upgrade guide.)
Now that we’ve gotten that out of the way, here is a selection of noteworthy changes in Rails 5:
WebSockets (Action Cable)
Have you ever wanted to spin up a server that just serves up JSON for your REST API? If so, you might want to check out the new Rails 5 API mode. Create your new application with the
--api option and you’ll get a slimmed down skeleton and configuration tailored to serving up JSON.
ActiveRecord attribute API
The Rails 5 attribute API gives you more control over how values are converted to and from SQL when assigned to your model. This makes things considerably simpler when working with custom data types. For example, you may want to use a custom money type for an attribute in your model. This attribute might contain a value such as “$5.00,” which is persisted as the integer 500 (representing the number of cents). We like this change because it establishes a pattern for using a custom data type in your model.
Halting callback chains
Before Rails 5, returning
false from any
before_ callback in
ActiveSupport would halt the callback chain. This implicit behavior could result in hard-to-diagnose issues when one of these callbacks unexpectedly evaluated to
In Rails 5, returning
false no longer halts the callback chain. Instead, if you want to halt the callback chain you do so explicitly by using
throw(:abort). We give this two thumbs up for code clarity.
Note that for backward compatibility, this behavior is configurable via
ActiveSupport.halt_callback_chains_on_return_false and will be enabled by default only in newly generated applications.
Rails 5 also gives some love to TestRunner. You are writing tests, right? If so, then you’ll probably like the fact that you can now run your tests directly from
rails test. Even better, you can run a single test by specifying the line number for the test as part of the command:
rails test test/controllers/foo_controller_test.rb:42. Another useful new feature is the ability to stop running tests when a test fails. Just pass the
If any of this resonates with you, then you’re ready to give Rails 5 a shot.
Curious about what else is new in Rails 5? Check out the release notes to learn more.
Wait, what about monitoring?
Yep, we promised to address monitoring, so glad you asked. The New Relic Ruby agent supports the official Rails 5 release right out of the gate, so you don’t have to wait to start using it.
We’ve been tracking Rails 5 development, bumping our test environments with each new beta, and even submitting pull requests to ensure we’re ready for Rails 5.0.0 when you are.
So what did we find? After some light massaging of version checks and some additional instrumentation for the new WebSockets framework, Action Cable, our metrics and events were flowing out of our test apps and right into our charts. (Thank you,
What this means for you is that your monitoring will continue to work just as you’ve come to expect, and your Action Cable metrics will appear seamlessly alongside the rest of your data.
What about the rest of Rails 5’s features, you ask? Another good question!
You can expect your new Active Record OR queries to appear under APM Datastores without any additional action on your part. If you’d like to give Rails 5’s API mode a try, we’ve got you covered there, too.
If you’re thinking, “Wow, this all sounds great. How do I take advantage of this in my new or recently upgraded Rails app?”, the process couldn’t be easier.
To ensure your Rails 5 app gets the monitoring it deserves, simply update to the latest version of the New Relic Ruby agent, and we’ll take care of the rest!