I'm facing a problem using the websocket-rails gem in my rails4 application.
The problem is that I cannot broadcast from my models.
see my model :
class Diffusion < ActiveRecord::Base
after_create :ws_update
def ws_update
WebsocketRails[:diffusions].trigger 'diffusions.new', {test: self.id}.to_json
end
end
from another rb file located under lib folder i'm calling this :
Diffusion.create(some_params)
I know for sure that my funtion ws_update is called and I can even see the logs into log/websockets_rails.log that the message has been sent.
There is my coffee/script that should handle the message in my web page
dispatcher = new WebSocketRails("localhost:3000/websocket")
channel = dispatcher.subscribe("diffusions")
channel.bind "diffusions.new", (data) ->
console.log "GOT DATAAAAAAA"
return
The "GOT DATAAAA" line is never display can you explain me why ?
Thanks
Read here: https://github.com/websocket-rails/websocket-rails/blame/712fd4e35325887956724be388821121a866c7fc/README.md#L177
Broadcast to the channel from anywhere inside your Rails application. An existing controller, a model, a background job, or a new WebsocketRails controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With