2

I'm busy with the creation of a collaborative application, where 2 users may edit the same data at the same time, without doing a full refresh of the HTML page (it is a huge table, as an excel sheet).

What is the best option in Rails 4 I have to push the modification from a user A to a user B ?

The ultimate goal should be to get an auto-update table like the one in google spreadsheet ! :-) I didn't find a recent (>2012) answer to this question... Is there a gem or a plugin that starts an automatic process on the server side ? How the manage the user subscriptions to udpates ?

Stéphane V
  • 1,094
  • 2
  • 11
  • 25
  • Nobody is using ActionController::Live and Server Sent Envents (SSE) ? This seems a better solution, isn't it ? – Stéphane V Mar 12 '14 at 12:52

2 Answers2

3

You should definitely use the websocket-rails gem, I am personnaly using it for a debate website which I'm creating from scratch.

It is using, as the name refers, Websockets. This technology is being more and more used, and is now compatible with most of the browsers, it has indeed an excellent compatibility.

websocket-rails has a lot of documentation, I also had some trouble using it for advanced usage, and got my happiness contacting their devs directly on their irc channel, they are very nice.

For your need, I think that Websockets are much more convenient than Ajax, for for your need, Ajax needs to ask the server each x second if there's something new to refresh. That will exhaust your server, but when using Websockets, the server will send you directly the new data that you need. You can find more info for this choice on this SO answer.

It handles private channels, if the data exchanged need not to be public as well, websocket-rails is definitely the way to go ! You can find it's repository here.

Community
  • 1
  • 1
sidney
  • 2,704
  • 3
  • 28
  • 44
  • Does websocket-rails use the same technology as Socket.IO? – OpenCoderX Mar 09 '14 at 12:36
  • @tester123 , yes it is the same technology as Socket.IO. Both are implementing it. However, Socket.IO is much more heavier, it's a real factory. IMO, websocket-rails is better for the rails implementation. – sidney Mar 09 '14 at 12:51
  • thanks. I've got websocket-rails working in dev. But I'm using nginx + passenger module in production, so I have to switch to Passenger standalone if I want to use websocket-rails in production. – OpenCoderX Mar 09 '14 at 16:42
  • Why so? Nginx is now websocket compatible (http://nginx.com/news/nginx-websockets/). Personally, I'm using Thin, and it works like a charm on Heroku. – sidney Mar 09 '14 at 17:18
  • After reading your comment, I found this: https://chrislea.com/2013/02/23/proxying-websockets-with-nginx/ – OpenCoderX Mar 10 '14 at 13:55
  • I confirm what I said earlier, this is much heavier to use **websockets** using `Node.JS` and `nginx`. Indeed, you got to install an entire framework... `Node.JS`, and to make it work with Rails. If you want to try this solution, you can follow this article: http://liamkaufman.com/blog/2012/02/25/adding_real-time_to_rails_with_socket.IO_nodejs_and_backbonejs_with_demo/ You will notice that it is still super heavy comparing to `websocket-rails` which exists only for **websockets** ;) – sidney Mar 10 '14 at 16:06
0

I will try to answer your question as simple as I can:

End of last year I created a web app that needed too many interactions and live updating on the client side. Basically like the Facebook Wall with notification and live updates.

I achieved this through using Private_Pub which is a Gem created based on Faye, by Ryan Bates, the author of RailstCasts There are tutorials and examples of using this for live updates.

However I don't advice you to use this, because you will end up doing so much dirty hacks and patches just to make sure the service is running and make sure connections are not closed and such.

My advice would be using a front-end JS on top of Rails Stack.

You can using Angular,Ember, Backbone and Meteor, all of them help you achieve that functionality on a safer side of things. Check out the RailsCasts for those Frameworks from Ryan Bates:

http://railscasts.com/episodes/408-ember-part-1

http://railscasts.com/episodes/351-a-look-at-meteor

http://railscasts.com/episodes/405-angularjs

http://railscasts.com/episodes/323-backbone-on-rails-part-1

0bserver07
  • 3,390
  • 1
  • 28
  • 56
  • 1
    I'm pretty sure you can't use meteor, it's not a front-end stack as such, afaik there's no rails plugin that would enable you to plug into meteor's websocket backend api, just open up firebug on any meteor app and you'll get what I mean – bbozo Mar 09 '14 at 10:43