4

We have a Rails app that acts HTTP API only. On the client side, Ember.js is currently used. We are not overly impressed by Ember and really like the approach Meteor.js takes. So we'd like to exchange the client side with Meteor.js and communicate with the Rails server via websockets that speak the Data Distribution Protocol (DDP), so we can keep using the models, mailers and controllers in Rails. Implementing server side of DDP should be easy.

However, we're unsure how to make Rails talk websockets. We found Reel, which seems to make it easy to accept websocket requests in a standalone environment. Reel seems great as we'd like to implement the DDP on top of the Celluloid stack anyway. But what about running Reel in the Rails environment? Would we need "rails runner" for that? And we'd like to keep using the existing controllers to dispatch incoming requests (like, to add/change/remove resources). Is that even possible without having the request coming through Rack?

Any input is appreciated.

Patrik
  • 95
  • 9
  • I don't know about the Rails stuff, but you can't use Meteor with it. Meteor is a full-stack framework; it handles both the client and server side. – Geoffrey Booth Apr 13 '14 at 17:17
  • 2
    In theory you can teach Rails to speak DDP but the bigger challenge is to implement real-time synch with your database, latency compensation, etc. If you just want to use the front-end part of Meteor w/o most of the features but still preserve the live-page updates (such as data-bindings), take a look at [Blaze](https://github.com/meteor/meteor/wiki/Using-Blaze) - Meteor's live page rendering engine. – imslavko Apr 14 '14 at 00:20
  • Thanks for your answers. Real-time sync should be easy. Just add after_create, after_update and after_destroy callbacks to the respective models and have the callbacks send the updates via DDP to the clients subscribed. I just don't know how to run a Celluloid::IO server in the context of Rails. Best practices? – Patrik Apr 15 '14 at 08:49

2 Answers2

4

It's a bit late, but I've implemented DDP in Ruby, you can check it out here:

https://github.com/d-snp/ruby-ddp-server

It includes an implementation of EJSON as well. It's built on top of celluloid-websocket, and can be ran simply as a rack app.

I've made an integration with RethinkDB that can be used as a reference to build your own collections implementation.

https://github.com/d-snp/ruby-ddp-server-rethinkdb

I've also made a sample chat application that can be found here:

https://github.com/d-snp/celluloid-rethinkdb-chat

Tinco
  • 597
  • 3
  • 14
2

It's something that I have been longing to do as well, to integrate old "legacy" Rails code. Here is the best way I have found:

Since you would not be using any of Rails router/controller/views, but just the ability to read data and push it to the client, I recommend you use Rails to create JSON apis to the database, and deploy the code, then in Meteor you can consume the data via the http package, this would happen on the server at a regular interval and populate the MongoDB with the normalized data you need, then it would serve the browser client.

I am working on such an application that will keep a normalized version of the data in Mongo, and a relational version of the data in mySql (through Rails) this way I can preserve the legacy Rails functionality that I dont want to rewrite in JS, and get the benefit of Meteor for the one page that I need it most.