admin管理员组

文章数量:1123692

Currently trying to implement a website with Ruby as my backend and React as my frontend. Checked that my frontend is already subscribed to the correct channel. When a new Model (TourGuidePackage) is created, it is able to invoke the after_commit method: broadcast_update.

To simulate the potential changes to Package Details like the name, i entered into a separate Ruby Console. Running

request = TourGuidePackage.last
request.name = "Changed Name"
request.save

The Rails logger in my broadcast_update runs normally but the ActionCable is not invoked. What is the potential issue?

def broadcast_update
    Rails.logger.info "Broadcast update ID: ${self.id}"
    payload = {id: self.id, message: "successfully updated"}
    ActionCable.server.broadcast(packageChannel, payload)

I tried to check if there is a potential disconnect in the user during the wait time but can confirm that the user was on. Also checked that broadcast_update is working for creation.

A weird thing i noticed is that when i did

ActionCable.server.broadcast(packageChannel, {id: 1, message: "successfully updated"}) 

on my Ruby Rails, it results in a nil and i cannot view the message on my frontend

I'm expecting to see the broadcasted message on the frontend but the message is not getting through. I'm hoping to stick to using ActionCable to achieve the communication between the frontend and backend

For context, i tried after_save and after_commit.

Appreciate any feedbacks for improvement

本文标签: reactjsFacing some issues with ActionCableStack Overflow