Jumpers over websocket rails using a channel

I am trying to use a push mechanism using the websocket-rails stone in a ROR application.

I basically did the following.

my application.js

//= require jquery //= require jquery_ujs //= require websocket_rails/main $(function(){ // connect to server like normal var dispatcher = new WebSocketRails('localhost:3000/websocket'); // subscribe to the channel var channel = dispatcher.subscribe('products'); // bind to a channel event channel.bind('new', function(data) { console.log('channel event received: ' + data); }); }); 

then I launched a thin server on port 3000

Then I from the rails console, I entered the following command.

 WebsocketRails[:products].trigger(:new, Product.last) 

But nothing was printed in the browser console.

Am I missing some configuration settings?

thanks

+4
source share
2 answers

I also came across this. The documentation says:

Transfer to the channel from anywhere in the Rails application. An existing controller, model, background job, or new WebsocketRails controller.

i.e. no mention of the console.

In my experience, it works exactly as described differently from the controller.

+2
source

I know this question is quite old, but there is some update in the project, so for everyone who comes here in the future, now use Synchronization between instance events can be run everywhere, even from the rails console.

Add this to your config/initializers/websocket_rails.rb

 WebsocketRails.setup do |config| config.synchronize = true end 
0
source

Source: https://habr.com/ru/post/1498989/


All Articles