Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern to integrate Rails with a Comet server

I have a Ruby on Rails (2.3.5) application and an APE (Ajax Push Engine) server. When records are created within the Rails application, i need to push the new record out on applicable channels to the APE server. Records can be created in the rails app by the traditional path through the controller's create action, or it can be created by several event machines that are constantly monitoring various inputstream and creating records when they see data that meets a certain criteria.

It seems to me that the best/right place to put the code that pushes the data out to the APE server (which in turn pushes it out to the clients) is in the Model's after_create hook (since not all record creations will flow through the controller's create action).

The final caveat is I want to push a piece of formatted HTML out to the APE server (rather than a JSON representation of the data). The reason I want to do this is 1) I already have logic to produce the desired layout in existing partials 2) I don't want to create a javascript implementation of the partials (javascript that takes a JSON object and creates all the HTML around it for presentation). This would quickly become a maintenance nightmare. The problem with this is it would require "rendering" partials from within the Model (which im having trouble doing anyhow because they don't seem to have access to Helpers when they're rendered in this manner).

Anyhow - Just wondering what the right way to go about organizing all of this is.

Thanks

like image 506
empire29 Avatar asked Jun 09 '10 05:06

empire29


1 Answers

After talking w some folks in #rails and #ape this is appears to be the best approach to this issue.

alt text

like image 140
empire29 Avatar answered Oct 22 '22 03:10

empire29