Ask A Question

Notifications

You’re not receiving notifications from this thread.

Question on ActionCable Group Chat part 4, development.rb fix for redis

Rob Sturcke asked in General

Saw in the comments the fix for (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) however I added the following to my development.rb:

  config.action_cable.allowed_request_origins = ['http://localhost:3000/']

Is that correct or should I be going to the following when I launch rails s:

redis://localhost:6379/1

(Sorry if this was already answered)

Reply

Yep, that'll work fine. You don't have to worry about the redis url at all for that. This is a validation to make sure that the browser origin (the domain that attempted to connect to the websocket) is an allowed one.

Basically you don't want someone on another website stealing your chat messages from another site, so this is a protection built-in for that.

It should default to allow localhost:3000, but it seems people are having trouble with that. Your solution is correct, and you'll add to that when you deploy it to production. 👍

Reply

Yeah I keep getting the error even after restarting rails s showing up though even with my line is now just config.action_cable.allowed_request_origins

.rvm/gems/ruby-2.3.0/gems/redis-3.3.1/lib/redis/client.rb:345:in `rescue in establish_connection': Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)
Reply

Your redis server isn't running. If you installed it with homebrew, you can type brew info redis to see the instructions on starting it up again.

Reply

Got ya! Didn't realize I had to install it through brew.

Reply

Yeah, it's now the default for Rails I believe, so it's a required dependency if you use the defaults. Super easy install with homebrew and everything should be automatically working for you after that.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,972+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.