I'm currently using Rails 6 and Linux mint Cinnamon 20.2, and I have problems with Redis configuration / setupping in my Rails application.My problem is that my ActionCable doesn't work well.
I would like to build a real time chat app, I created a channel, called "Room".Here how my room_channel.js file looks like:
import consumer from "./consumer"consumer.subscriptions.create({ channel: "RoomChannel", room_id: 3 }, {connected() { console.log('Connected successfully!')},disconnected() { // Called when the subscription has been terminated by the server},received(data) { console.log(data)}});
Here's my room_channel.rb:
class RoomChannel < ApplicationCable::Channeldef subscribed stream_from "room_channel_#{params[:room_id]}"enddef unsubscribed # Any cleanup needed when channel is unsubscribedendend
Here's the important segment of my messages_controller.rb file (The ActionCable command is the important):
def create @message = Message.new(message_params) @message.user = User.generate @message.save ActionCable.server.broadcast("room_channel_#{@message.room_id}",{message:"hello"})end
When I join to Room 3 (3 is the ID of that room), I get my "Connected successfully" message, but when I send a message, it doesn't output "hello" in the console. It means it doesn't receive successfully datas, right?
What can i do with Redis to be able to receive data?
Finally, I changed the development section of my config/cable.yml file to, but it doesn't solved anything :(.
development: adapter: redis url: redis://localhost:6379/1
Anybody can help me out with this?Thanks for your help!