Design pattern for integrating Rails with the Comet server

I have a Ruby on Rails application (2.3.5) and an APE server (Ajax Push Engine). When the entries are created in the Rails application, I need to output the new entry to the appropriate channels on the APE server. Records can be created in the rails application in the traditional way by creating a controller, or can be created by several event computers that constantly monitor various input streams and create records when they see data that meets certain criteria.

It seems to me that the best / right place to post code that pushes data to the APE server (which, in turn, pushes it for clients) is in the after_create model trailer (since not all records are created, the stream through the controller creates an action).

One final caveat - I want to push a piece of formatted HTML to the APE server (and not to the JSON representation of the data). The reason I want to do this: 1) I already have the logic to create the desired layout in existing particles. 2) I don’t want to create a javascript implementation of partial ones (javascript that takes a JSON object and creates all the HTML around this for presentation). This will quickly become a service nightmare. The problem with this is that it will require partial processing of the “rendering” inside the model (which they fail to do anyway because they don’t have access to helpers when they are displayed in this way).

In any case, it’s just interesting what the right way to organize all this is.

thanks

+6
design-patterns ruby-on-rails comet renderpartial
source share
1 answer

After talking with some people in #rails and #ape, this is the best approach to this problem.

alt text

+8
source share

All Articles