What’s New in Rails 5

Share this article

rail5

Rails 5 is right around the corner (currently targeting Fall 2015) and there are some exciting features coming up. If you are running a Rails shop, you need to prepare your apps for this major release.

Don’t worry. As always, we at Sitepoint will guide you throughout the migration process when the release date approaches. For now, let’s catch you up on what’s coming and how it will improve your development process.

Major Improvements

There are some amazing announcements that will fundamentally shift how we work with Rails. New features like Action Cable and improved Turbolinks that can instantly improve our web development workflow. Let’s look at each of them in detail.

Merging Rails API

Over the last few years, many thanks to Backbone.js and Angular.JS, the number of Single Page Applications (SPAs) are on the rise. The last few projects that I have built have been purely SPA and using Rails for these cases was an overkill. I tried dabbling with Sinatra and even pure Rack applications, but ended up writing too much boilerplatee. The routing was lacking compared to Rails and there were too many security vulnerabilities that I had to handle. I had to either write it on top of the community driven rails-api gems or live with traditional Rails.

In Rails 5, the rails-api gem will be merged into core allowing the use of Rails as a simple JSON API. Personally, I find this a great addition. I won’t have to look further while building an API for my javascript (and other) appliciation clients.

Ruby 2.2.1

Ruby 2.2 was a great addition to the Ruby community. Not only did it bring a huge performance boost to Ruby, but it also introduced a slew of new functions. In addition, garbage collection of symbols was widely celebrated. Legend has it that Dragons of Valeria rained down rose petals on the Seventh Kingdom when this announcement was made. OK! Maybe I took that too far, but you get the general picture.

NOTE: Before migrating to Rails 5 you need to make sure that your app works on Ruby 2.2.1.

Due to these enhancements, Ruby 2.2+ was a ripe candidate for Rails 5. Rails 5 will only work on Ruby 2.2.1 and above.

Turbolinks 3

Traditional web apps tend to be slow due to full page reloads. One way to solve this is just reloading the bare minimum content area. Turbolinks solve this by just reloading the contents of the body from the server, instead of refreshing the entire page. While this improves the performance to a certain extent, this is also relatively slow. Turbolinks 3 aims to solve this.

Tubolinks 3 allows you to retain most of your page and selectively update certain regions through partials. This is very similar to how SPA’s work, and you can choose to do all this from the server. Sounds great, right?

This is a great feature as the flock moves towards single page apps. However, at first glance, it looks like you’ll have to manage the partials manually. This means that you’ll have to remember which part of the app to reload at a specific point. To me, it adds a lot of clutter to my code and makes it easy to screw up. Personally, I prefer using something like React, which handles this very well with the Virtual DOM.

Note: The way React works is, it maintains a Virtual DOM where all the manipulations happen. It then diff’s the Virtual DOM and the actual DOM and makes only the required changes. It ensures that DOM is hit only when absolutely required and the changes are bare minimum.

Having said that, for the folks who don’t like to meddle around with JS, this offers an instantaneous performance boost.

Action Cable

Many projects these days use WebSockets to push live updates to the client. While most client browsers have started to support this, we still need a robust client on the server to manage the subscribers and send an update signal appropriately. This feature is available out of the box in some of the newer frameworks, like Phoenix for Erlang. However, the Rails community had to resort to third party implementations, like Pushr, to get this working.

Note: For the uninitiated, WebSockets is a W3C standard that opens up a duplex connection from your browser. Servers can talk (i.e., push updates) to clients as needed, and asynchronously update the client’s state without a full page reload. For instance, this is how Gmail loads new emails without reloading the entire page.

Rails traditionally offers all the tools that one needs to build a great app out of the box. That’s one reason why it is so popular, especially among the startup community. The lack of WebSocket support was a reason for major discontent among the community. It looks like the Rails core team took note of this and came up with Action Cable. We’ll have to wait for some time to see how this is going to work in real life, but it’s exciting nevertheless.

Some Niceties

Rake Inside Rails

For many a Rails noob, having to figure out when to use rake and when to use rails is a source of confusion. Now you don’t need to switch context between the rake and rails commands. You can run all Rake tasks with the rails keyword. For instance,

rake db:migrate

will now become:

rails db:migrate

This may not look like much on the surface, but this will make the lives of beginners much simpler. Rails 5 will also add a restart command that quickly restarts the application.

Active Record Changes

One change that almost went unnoticed was the update to belongs_to. When you create a Student belongs_to Class relation, it was possible to create a student without an associated Class relation. This lead to a lot of data inconsistencies. With Rails 5, he parent has become mandatory. If you try to insert an empty record here, Active Record will throw up.

Changes to Controller Tests

If you’re testing what your template renders in your controller, you are doing it wrong. A simple change to your template will leave you with sleepless nights, hunting down the culprit. That’s why, in Rails 5, assert_template is deprecated. However, you can continue using assert_select to check if a specific DOM element is present.

If you’ve been testing the instance variables inside a controller method, you should note that assigns is also going away.

If you’re writing controller tests, the new decree is that you should be concerned with cookies, HTTP return code, and DB calls, if any. Wait, that sounds just like an integration test. Well, you got me there…controller tests will likely be dropped in favor of integration tests in the future.

Note:* Checkout Rails Dom testing for more details and best practices.

Wrapping Up

With javascript playing a dominant role in web development today, web frameworks are getting reduced to mere API services. The Rails core team realizes this and is moving in the right direction. Feel free to join us in the comments section for a discussion.

Frequently Asked Questions about Rails 5

What are the major changes in Rails 5 compared to Rails 4?

Rails 5 introduced several significant changes compared to Rails 4. The most notable ones include Action Cable, a new framework that integrates WebSockets with the rest of your Rails application. It allows for real-time features to be written in Ruby in the same style and form as the rest of your Rails application. Another major change is the introduction of API mode, which allows you to create a slimmed-down Rails application, ideal for API-only applications. Rails 5 also introduced Turbolinks 5, which allows you to create Single Page like Applications directly from Rails stack, without having to resort to a heavier SPA framework.

What is Action Cable in Rails 5?

Action Cable is a new feature in Rails 5 that integrates WebSockets with the rest of your Rails application. It allows for real-time features to be written in Ruby in the same style and form as the rest of your Rails application. This means you can write real-time applications with Rails, introducing a level of interactivity and responsiveness that was previously difficult to achieve.

How does API mode work in Rails 5?

API mode in Rails 5 is a way to create a slimmed-down Rails application, ideal for API-only applications. When you create a new Rails application using API mode, it starts with a smaller set of middleware than typical. It also omits any middleware for handling cookies or sessions, making it a leaner and more efficient framework for API-only applications.

What is Turbolinks 5 in Rails 5?

Turbolinks 5 is a feature in Rails 5 that allows you to create Single Page like Applications directly from Rails stack, without having to resort to a heavier SPA framework. It makes navigating your web application faster by using JavaScript to replace the page content when you follow a link, without needing to reload the entire page.

How does Rails 5 improve test runner?

Rails 5 introduced a new test runner that enhances the testing experience. It includes features like colorized output, the ability to test specific lines of code, and smart test re-running. It also provides options to stop running tests after the first failure, making it easier to debug and fix issues.

What is the purpose of ApplicationRecord in Rails 5?

ApplicationRecord is a new superclass for all models in Rails 5. It’s an abstract class that sits above all of your app’s models, similar to how ApplicationController works for controllers. This allows you to specify default behavior for all models in one place.

How does Rails 5 handle JavaScript dependencies?

Rails 5 introduced a new way to handle JavaScript dependencies with the new Rails Command Line Interface (CLI). The new CLI includes commands for adding JavaScript dependencies directly into your Rails application, making it easier to manage and update your JavaScript libraries.

What is the purpose of the ‘rails’ command in Rails 5?

The ‘rails’ command in Rails 5 is a new command line interface that replaces the old ‘rake’ command. It provides a unified command line interface for all tasks, including running tests, starting a server, and creating new resources.

How does Rails 5 improve support for PostgreSQL?

Rails 5 introduced several improvements for PostgreSQL. It added support for the ‘belongs_to’ association required by default, materialized views, and the ability to add foreign keys in parallel, among other features. These enhancements make it easier to work with PostgreSQL in Rails applications.

What are the system requirements for Rails 5?

Rails 5 requires Ruby 2.2.2 or newer. It also requires a working installation of SQLite3, unless you’re using a different database. For development, you’ll need a Unix-like operating system such as Linux or macOS. Windows is also supported, but you may need to install additional software.

Hola! I'm a Fullstack developer and a strong advocate of Mobile first design. I'm running a digital children's startup for kids and I lead the engineering efforts there. In my free time I ramble about technology, and consult startups.

GlennG
Share this article
Read Next
7 Easy Ways to Make a Magento 2 Website Faster
7 Easy Ways to Make a Magento 2 Website Faster
Konstantin Gerasimov
Powerful React Form Builders to Consider in 2024
Powerful React Form Builders to Consider in 2024
Femi Akinyemi
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Ralph Mason
Sending Email Using Node.js
Sending Email Using Node.js
Craig Buckler
Creating a Navbar in React
Creating a Navbar in React
Vidura Senevirathne
A Complete Guide to CSS Logical Properties, with Cheat Sheet
A Complete Guide to CSS Logical Properties, with Cheat Sheet
Ralph Mason
Using JSON Web Tokens with Node.js
Using JSON Web Tokens with Node.js
Lakindu Hewawasam
How to Build a Simple Web Server with Node.js
How to Build a Simple Web Server with Node.js
Chameera Dulanga
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Beloslava Petrova
Crafting Interactive Scatter Plots with Plotly
Crafting Interactive Scatter Plots with Plotly
Binara Prabhanga
GenAI: How to Reduce Cost with Prompt Compression Techniques
GenAI: How to Reduce Cost with Prompt Compression Techniques
Suvoraj Biswas
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
Aurelio De RosaMaria Antonietta Perna
Quick Tip: How to Align Column Rows with CSS Subgrid
Quick Tip: How to Align Column Rows with CSS Subgrid
Ralph Mason
15 Top Web Design Tools & Resources To Try in 2024
15 Top Web Design Tools & Resources To Try in 2024
SitePoint Sponsors
7 Simple Rules for Better Data Visualization
7 Simple Rules for Better Data Visualization
Mariia Merkulova
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
SitePoint Team
Best Programming Language for AI
Best Programming Language for AI
Lucero del Alba
Quick Tip: How to Add Gradient Effects and Patterns to Text
Quick Tip: How to Add Gradient Effects and Patterns to Text
Ralph Mason
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Vultr
How to Optimize Website Content for Featured Snippets
How to Optimize Website Content for Featured Snippets
Dipen Visavadiya
Psychology and UX: Decoding the Science Behind User Clicks
Psychology and UX: Decoding the Science Behind User Clicks
Tanya Kumari
Build a Full-stack App with Node.js and htmx
Build a Full-stack App with Node.js and htmx
James Hibbard
Digital Transformation with AI: The Benefits and Challenges
Digital Transformation with AI: The Benefits and Challenges
Priyanka Prajapat
Quick Tip: Creating a Date Picker in React
Quick Tip: Creating a Date Picker in React
Dianne Pena
How to Create Interactive Animations Using React Spring
How to Create Interactive Animations Using React Spring
Yemi Ojedapo
10 Reasons to Love Google Docs
10 Reasons to Love Google Docs
Joshua KrausZain Zaidi
How to Use Magento 2 for International Ecommerce Success
How to Use Magento 2 for International Ecommerce Success
Mitul Patel
5 Exciting New JavaScript Features in 2024
5 Exciting New JavaScript Features in 2024
Olivia GibsonDarren Jones
Tools and Strategies for Efficient Web Project Management
Tools and Strategies for Efficient Web Project Management
Juliet Ofoegbu
Choosing the Best WordPress CRM Plugin for Your Business
Choosing the Best WordPress CRM Plugin for Your Business
Neve Wilkinson
ChatGPT Plugins for Marketing Success
ChatGPT Plugins for Marketing Success
Neil Jordan
Managing Static Files in Django: A Comprehensive Guide
Managing Static Files in Django: A Comprehensive Guide
Kabaki Antony
The Ultimate Guide to Choosing the Best React Website Builder
The Ultimate Guide to Choosing the Best React Website Builder
Dianne Pena
Exploring the Creative Power of CSS Filters and Blending
Exploring the Creative Power of CSS Filters and Blending
Joan Ayebola
How to Use WebSockets in Node.js to Create Real-time Apps
How to Use WebSockets in Node.js to Create Real-time Apps
Craig Buckler
Best Node.js Framework Choices for Modern App Development
Best Node.js Framework Choices for Modern App Development
Dianne Pena
SaaS Boilerplates: What They Are, And 10 of the Best
SaaS Boilerplates: What They Are, And 10 of the Best
Zain Zaidi
Understanding Cookies and Sessions in React
Understanding Cookies and Sessions in React
Blessing Ene Anyebe
Enhanced Internationalization (i18n) in Next.js 14
Enhanced Internationalization (i18n) in Next.js 14
Emmanuel Onyeyaforo
Essential React Native Performance Tips and Tricks
Essential React Native Performance Tips and Tricks
Shaik Mukthahar
How to Use Server-sent Events in Node.js
How to Use Server-sent Events in Node.js
Craig Buckler
Five Simple Ways to Boost a WooCommerce Site’s Performance
Five Simple Ways to Boost a WooCommerce Site’s Performance
Palash Ghosh
Elevate Your Online Store with Top WooCommerce Plugins
Elevate Your Online Store with Top WooCommerce Plugins
Dianne Pena
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Dianne Pena
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
Vultr
Enhance Your React Apps with ShadCn Utilities and Components
Enhance Your React Apps with ShadCn Utilities and Components
David Jaja
10 Best Create React App Alternatives for Different Use Cases
10 Best Create React App Alternatives for Different Use Cases
Zain Zaidi
Control Lazy Load, Infinite Scroll and Animations in React
Control Lazy Load, Infinite Scroll and Animations in React
Blessing Ene Anyebe
Building a Research Assistant Tool with AI and JavaScript
Building a Research Assistant Tool with AI and JavaScript
Mahmud Adeleye
Understanding React useEffect
Understanding React useEffect
Dianne Pena
Web Design Trends to Watch in 2024
Web Design Trends to Watch in 2024
Juliet Ofoegbu
Building a 3D Card Flip Animation with CSS Houdini
Building a 3D Card Flip Animation with CSS Houdini
Fred Zugs
How to Use ChatGPT in an Unavailable Country
How to Use ChatGPT in an Unavailable Country
Dianne Pena
An Introduction to Node.js Multithreading
An Introduction to Node.js Multithreading
Craig Buckler
How to Boost WordPress Security and Protect Your SEO Ranking
How to Boost WordPress Security and Protect Your SEO Ranking
Jaya Iyer
Understanding How ChatGPT Maintains Context
Understanding How ChatGPT Maintains Context
Dianne Pena
Building Interactive Data Visualizations with D3.js and React
Building Interactive Data Visualizations with D3.js and React
Oluwabusayo Jacobs
JavaScript vs Python: Which One Should You Learn First?
JavaScript vs Python: Which One Should You Learn First?
Olivia GibsonDarren Jones
13 Best Books, Courses and Communities for Learning React
13 Best Books, Courses and Communities for Learning React
Zain Zaidi
5 jQuery.each() Function Examples
5 jQuery.each() Function Examples
Florian RapplJames Hibbard
Implementing User Authentication in React Apps with Appwrite
Implementing User Authentication in React Apps with Appwrite
Yemi Ojedapo
AI-Powered Search Engine With Milvus Vector Database on Vultr
AI-Powered Search Engine With Milvus Vector Database on Vultr
Vultr
Understanding Signals in Django
Understanding Signals in Django
Kabaki Antony
Why React Icons May Be the Only Icon Library You Need
Why React Icons May Be the Only Icon Library You Need
Zain Zaidi
View Transitions in Astro
View Transitions in Astro
Tamas Piros
Getting Started with Content Collections in Astro
Getting Started with Content Collections in Astro
Tamas Piros
What Does the Java Virtual Machine Do All Day?
What Does the Java Virtual Machine Do All Day?
Peter Kessler
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Mayank Singh
Layouts in Astro
Layouts in Astro
Tamas Piros
.NET 8: Blazor Render Modes Explained
.NET 8: Blazor Render Modes Explained
Peter De Tender
Mastering Node CSV
Mastering Node CSV
Dianne Pena
A Beginner’s Guide to SvelteKit
A Beginner’s Guide to SvelteKit
Erik KückelheimSimon Holthausen
Brighten Up Your Astro Site with KwesForms and Rive
Brighten Up Your Astro Site with KwesForms and Rive
Paul Scanlon
Which Programming Language Should I Learn First in 2024?
Which Programming Language Should I Learn First in 2024?
Joel Falconer
Managing PHP Versions with Laravel Herd
Managing PHP Versions with Laravel Herd
Dianne Pena
Accelerating the Cloud: The Final Steps
Accelerating the Cloud: The Final Steps
Dave Neary
An Alphebetized List of MIME Types
An Alphebetized List of MIME Types
Dianne Pena
The Best PHP Frameworks for 2024
The Best PHP Frameworks for 2024
Claudio Ribeiro
11 Best WordPress Themes for Developers & Designers in 2024
11 Best WordPress Themes for Developers & Designers in 2024
SitePoint Sponsors
Top 10 Best WordPress AI Plugins of 2024
Top 10 Best WordPress AI Plugins of 2024
Dianne Pena
20+ Tools for Node.js Development in 2024
20+ Tools for Node.js Development in 2024
Dianne Pena
The Best Figma Plugins to Enhance Your Design Workflow in 2024
The Best Figma Plugins to Enhance Your Design Workflow in 2024
Dianne Pena
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Christopher Collins
Build Your Own AI Tools in Python Using the OpenAI API
Build Your Own AI Tools in Python Using the OpenAI API
Zain Zaidi
The Best React Chart Libraries for Data Visualization in 2024
The Best React Chart Libraries for Data Visualization in 2024
Dianne Pena
7 Free AI Logo Generators to Get Started
7 Free AI Logo Generators to Get Started
Zain Zaidi
Turn Your Vue App into an Offline-ready Progressive Web App
Turn Your Vue App into an Offline-ready Progressive Web App
Imran Alam
Clean Architecture: Theming with Tailwind and CSS Variables
Clean Architecture: Theming with Tailwind and CSS Variables
Emmanuel Onyeyaforo
How to Analyze Large Text Datasets with LangChain and Python
How to Analyze Large Text Datasets with LangChain and Python
Matt Nikonorov
6 Techniques for Conditional Rendering in React, with Examples
6 Techniques for Conditional Rendering in React, with Examples
Yemi Ojedapo
Introducing STRICH: Barcode Scanning for Web Apps
Introducing STRICH: Barcode Scanning for Web Apps
Alex Suzuki
Using Nodemon and Watch in Node.js for Live Restarts
Using Nodemon and Watch in Node.js for Live Restarts
Craig Buckler
Task Automation and Debugging with AI-Powered Tools
Task Automation and Debugging with AI-Powered Tools
Timi Omoyeni
Quick Tip: Understanding React Tooltip
Quick Tip: Understanding React Tooltip
Dianne Pena
12 Outstanding AI Tools that Enhance Efficiency & Productivity
12 Outstanding AI Tools that Enhance Efficiency & Productivity
Ilija Sekulov
React Performance Optimization
React Performance Optimization
Blessing Ene Anyebe
Introducing Chatbots and Large Language Models (LLMs)
Introducing Chatbots and Large Language Models (LLMs)
Timi Omoyeni
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Ampere Computing
Scale Your React App with Storybook and Chromatic
Scale Your React App with Storybook and Chromatic
Daine Mawer
10 Tips for Implementing Webflow On-page SEO
10 Tips for Implementing Webflow On-page SEO
Milan Vracar
Get the freshest news and resources for developers, designers and digital creators in your inbox each week