Reputation: 261
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
Upvotes: 3
Views: 272
Reputation: 2732
Broadcast to the channel from anywhere inside your Rails application. An existing controller, a model, a background job, or a new WebsocketRails controller.
Upvotes: 1