Tuesday, April 30, 2024
HomeRuby On RailsPlugging in AnyCable | Drifting Ruby

Plugging in AnyCable | Drifting Ruby


# Terminal
rails g channel welcome

brew set up anycable-go

anycable-go --host=localhost --port=3334
anycable

bundle exec anycable --server-command "anycable-go --host=localhost --port=3334"
# app/javascript/channels/welcome_channel.js
obtained(information) {
  // Known as when there's incoming information on the websocket for this channel
  console.log(information)
}
# app/channels/welcome_channel.rb
def subscribed
  stream_from "welcome_channel"
finish
# controllers/welcome_controller.rb
def index
  ActionCable.server.broadcast('welcome_channel', Time.now)
finish
# Gemfile
gem "anycable-rails"
gem "redis"
# config/cable.yml
growth:
  adapter: any_cable
# config/anycable.yml
growth:
  redis_url: redis://localhost:6379/1
  access_logs_disabled: false
# config/environments/growth.rb
config.action_cable.url = "ws://localhost:3334/cable"
# app/views/layouts/software.html.erb
<%= action_cable_meta_tag %>
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments