BigBinary Blog

We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.

Rails 6 Pass custom config to ActionCable::Server::Base

This blog is part of our Rails 6 series.

Rails 6.0 was recently released.

Before Rails 6, Action Cable server used default configuration on boot up, unless custom configuration is provided explicitly.

Custom configuration can be mentioned in either config/cable.yml or config/application.rb as shown below.

1# config/cable.yml
4  url: redis://
5  adapter: redis
6  channel_prefix: custom_


1# config/application.rb
3config.action_cable.cable = { adapter: "redis", channel_prefix: "custom_" }

In some cases, we need another Action Cable server running separately from application with a different set of configuration.

Problem is that both approaches mentioned earlier set Action Cable server configuration on application boot up. This configuration can not be changed for the second server.

Rails 6 has added a provision to pass custom configuration. Rails 6 allows us to pass ActionCable::Server::Configuration object as an option when initializing a new Action Cable server.

2config =
3config.cable = { adapter: "redis", channel_prefix: "custom_" }
4 config)

For more details on Action Cable configurations, head to Action Cable docs.

Here's the relevant pull request for this change.

Taha Husain in Rails 6
August 21, 2019

Subscribe to our newsletter