5

I created a project on Rails 5.0.0.

Further I did absolutely the same as in this video: https://www.youtube.com/watch?v=n0WUjGkDFS0

Except for the generated channels. I generated two channels: chat and comment.

I also read it in parallel: https://github.com/rails/rails/tree/master/actioncable

In routes.rb I added this line:

mount ActionCable.server => '/cable'

In application.rb I added this line:

config.action_cable.mount_path = '/cable'

As a result, I run a project of this command:

rails server -b SERVER_IP -p 3020

This error is displayed in the console browser:

WebSocket connection to 'ws://site.com/cable' failed: Unexpected response code: 404

A piece of the log by running the project:

Started GET "/cable" for SERVER_IP at 2016-07-12 16:20:14 +0300
Cannot render console from SERVER_IP! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started GET "/cable/" [WebSocket] for SERVER_IP at 2016-07-12 16:20:14 +0300
Request origin not allowed: example.com
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for SERVER_IP at 2016-07-12 16:20:14 +0300

The error may be what? What am I doing wrong?

Definitions:

  • SERVER_IP - this disguised the original IP address of the server.

  • example.com - this disguised the original URL of the site.

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
Colibri
  • 993
  • 11
  • 29
  • Could be a duplicate, try this (substituting `development` for whatever environment you're running in): http://stackoverflow.com/a/35442353/2076787 – D-side Jul 12 '16 at 20:11
  • @D-side More to such people as you. Thank you for not abandoned me and pointed to the problem. THANK YOU! – Colibri Jul 12 '16 at 22:02
  • I take it **it really is** a duplicate? – D-side Jul 12 '16 at 22:30
  • @D-side Difficult question. This line does not help in development.rb file. But it helps application.rb file. I add this: ```config.action_cable.allowed_request_origins = ['http:// site.com']``` – Colibri Jul 12 '16 at 22:41
  • Yeah, read stuff in parens: you don't appear to be running your app in development mode, so you should be fixing a file that corresponds to the environment you're using, `production.rb`, I guess, but you might know better. (Not to leave out the possibility that there is a bug somewhere inside) – D-side Jul 12 '16 at 22:52

1 Answers1

5

Make sure you have added these lines in your development.rb file

config.action_cable.url = "ws://localhost:3000/cable"

config.action_cable.allowed_request_origins = [/http:\/\/*/, 
/https:\/\/*/]