0

I just upgraded my app to Rails 5, I'm following a tutorial about ActionCable basics, but I cannot start a server.

Everytime I try to do so, I get the following error:

uninitialized constant ActionCable (NameError)

It seems like it comes from my routes.rb file, from this line :

mount ActionCable.server => '/cable'

This line is specified in every tutorial I've read so far, so I assume it is required for Actioncable to work. Has anyone encountered this problem before ? My gemfile is up-to-date, i'm using rails 5.0.0.1

Pierre Olivier Tran
  • 817
  • 1
  • 7
  • 15

2 Answers2

1

If you are sure that you are declaring the channel and connection files in the correct place, then make sure you are loading ActionCable in config/application.rb.

You may have something like the following in this file:

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"

In which case you just need to add require "action_cable/engine".

Or, if you prefer you can use require "rails/all" to load all the frameworks as once. The Rails Initialization Process guide has more detail about this.

rails/all loads the following:

  active_record/railtie
  action_controller/railtie
  action_view/railtie
  action_mailer/railtie
  active_job/railtie
  action_cable/engine
  rails/test_unit/railtie
  sprockets/railtie
tomsabin
  • 265
  • 2
  • 6
0

As per this answer, make sure you have followed the following file path. You need app/channels/application_cable/channel.rb that look like this.

module ApplicationCable
  class Channel < ActionCable::Channel::Base
  end
end

and app/channels/application_cable/connection.rb

module ApplicationCable
  class Connection < ActionCable::Connection::Base
  end
end
Community
  • 1
  • 1
Jayaprakash
  • 1,407
  • 1
  • 9
  • 19