0

I am trying to use the merit gem to handle points and badges for a website. I want certain javascript animations/events to fire when the user the achieves certain things. IE, when the point score increases it shows an animation of their score going up, or when they earn a badge an modal pops up showing the badge they earned etc.

I am just looking for advice on how to organize or do this. The merit activity log doesn't record events when using the add_points function? Also the Observer class is not called when this happens? The application can add_points from all over in dynamic ways so using the rules doesn't really work for things besides getting points for leaving comments, registering etc. (We have people answering quizzes and getting different totals based on how many times they answered wrong). Also with rails you can't or are not supposed to set flash messages from an observer just a controller.

One way I was looking into this was setting up an extra custom activity feed and having javascript on an interval looking for updates of events yet shown and then firing, but this doesn't seem ideal and taxing on the server.

Basically it is really random where badges and points can be set all over the application, and I want something sitting there knowing when one of these things happens, and fires the correct javascript when it does. Any advice on doing this would be greatly appreciated.

Nigel Kehler
  • 13
  • 1
  • 3

1 Answers1

0

With Rails Observers you can watch the badges_sashes and the score_points tables, both of which change regardless of when and how did reputation change.

Then you'll have your custom app observer, outside of merit. From there, you can either do server side push events, or do polling from the browser to the server to display notifications to the client.

TuteC
  • 4,342
  • 30
  • 40