Adam Niedzielski

Solve business problems with high quality code

How to remove Action Cable from a Rails app

| Comments

This is your complete guide to removing Action Cable from a Rails 5 app.

Some people need WebSockets in their app while other people do not need it at all or want to use other solution such as message_bus. Keep your application clean and delete Action Cable specific stuff.

Updated: 20.08.2016

Scenarios:

  1. I am upgrading from Rails 4
  2. I generated Rails 5 app with Action Cable
  3. I want to generate Rails 5 app without Action Cable

I am upgrading from Rails 4

1) Open config/application.rb.

2) If the file contains

1
require 'rails/all'

your are unnecessarily loading Action Cable code.

3) Replace require 'rails/all' with:

1
2
3
4
5
6
7
8
9
10
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"

I generated Rails 5 app with Action Cable

1) If in config/application.rb you have require 'rails/all' – replace it with:

1
2
3
4
5
6
7
8
9
10
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"

2) If in config/application.rb you have require "action_cable/engine" – remove this line.

3) Remove app/assets/javascripts/cable.js file.

4) Remove app/assets/javascripts/channels directory.

5) Remove app/channels directory.

6) Remove config/cable.yml file.

7) From config/environments/production.rb remove

1
2
3
4
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

8) From Gemfile remove:

1
2
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'

9) If you added action_cable_meta_tag to app/views/layouts/application.html.erb, remove it from there.

I want to generate Rails 5 app without Action Cable

rails new my-app-name --skip-action-cable


If there is anything missing in this guide, please let me know! I want to keep it complete.

Comments