Rails now supports routes prefixed with word cable

ActionCable seamlessly integrates WebSockets with the rest of our Rails application. It allows for real-time features to be written in Ruby in the same style and form the rest of our Rails application, while still being performant and scalable. It’s a full-stack offering that provides both a client-side JavaScript framework and a server-side Ruby framework. We have access to our entire domain model written with ActiveRecord or ORM of our choice.

Rails have resourceful routing. Resource routing allows us to quickly declare all of the common routes for a given resourceful controller. A single call to resources can declare all of the necessary routes for our index, show, new, edit, create, update, and destroy actions.

Earlier, whenever we navigate to a route prefixed with the word cable like /cable-slug resulted in a 404 error. Now it got fixed with the recent release.

Before

Navigating to a route that is prefixed with #{Rails.application.config.action_cable.mount_path}- 404s But navigating to a route that is prefixed with #{Rails.application.config.action_cable.mount_path}_ works.

http://localhost:3000/cable-hypenated-slug -> 404
http://localhost:3000/cable_underscored_slug -> 200

The same is true regardless of the mount path:

# config.action_cable.mount_path = "/dev/cable"

http://localhost:3000/dev/cable-hyphenated-slug -> 404
http://localhost:3000/dev/cable_underscored_slug -> 200

After

Thanks to this PR: with this latest Rails version v7.0.4 it is possible to navigate to routes prefixed with word cable.

The ActionCable server is now mounted with anchor: true.

This means that routes that also start with /cable will no longer clash with Action Cable.

http://localhost:3000/cable-hypenated-slug -> 200
http://localhost:3000/cable_underscored_slug -> 200

http://localhost:3000/dev/cable-hyphenated-slug -> 200
http://localhost:3000/dev/cable_underscored_slug -> 200

Need help on your Ruby on Rails or React project?

Join Our Newsletter