3

Trying to implement a simple notification system based on private pub ( something like juggernaut ). by Ryan bates see: http://railscasts.com/episodes/316-private-pub

Problem: Im unable to send a message true private pub from a controller

Some code:

inside header.haml

= subscribe_to "/notifications"
= javascript_include_tag APP_CONFIG['faye'] ( includes JS wich is correct )

inside application.coffee

PrivatePub.subscribe "/notifications", (data, channel) ->
alert data

inside any controller action

PrivatePub.publish_to("/notifications", "some test data to send")

-

This does not work, wanted behavior is that the "some test data to send " is being displayed in an alert on any page I'm on in the rails app. Ive tried several times the tutorial on rails cast, cloned the private pub example code repo, but nothing works sending from a controller.

UPDATE:

Anyone could help provide a example of private pub app in a repro publishing to a channel from a controller?

UPDATE2 It seems as long as there is a create action it works, but without a create action it is not. I would like to be able to just send some data from anywhere in a controller to the app with a javascript command. Like " send private pub message load popup " for example, what do i Missi n above code that makes this not work?

Khaled
  • 2,101
  • 1
  • 18
  • 26
Rubytastic
  • 15,001
  • 18
  • 87
  • 175
  • 1
    Is `alert data` indented properly or is that a typo in the second listing? I have an old app that publishes using PrivatePub from a controller: https://github.com/BinaryMuse/chatterbox/blob/9d62868e04525f9a2e746bcad059f7fb72644634/app/controllers/rooms_controller.rb#L55. [Here is the JavaScript](https://github.com/BinaryMuse/chatterbox/blob/9d62868e04525f9a2e746bcad059f7fb72644634/public/javascripts/room.js#L10-23) (this was a pre-Asset Pipeline app). – Michelle Tilley Mar 05 '12 at 01:09
  • Previously did not found your project on Github, interesting you use mongodb to store data in, very interested code Im going to study it bit thx! – Rubytastic Mar 05 '12 at 01:55
  • Yeah, using MongoDB to store chats so when you refresh/return to the page it has state. Probably better storage engines for this task (Redis comes to mind) :) – Michelle Tilley Mar 05 '12 at 05:17
  • Brandon if you answer question in follow up reply I can grand you the bounty believe I cannot do that true a comment. thx – Rubytastic Mar 11 '12 at 14:52

2 Answers2

0

Private Pub doesn’t allow you to send messages through the controller. Instead you should respond with a JavaScript that does that on the client. It's all described in this great Faye and PrivatePub tutorial

Yossi Shasho
  • 3,632
  • 31
  • 47
0

I finally fixed the issues, since no real answers I grant to Brandon if thats possible

Rubytastic
  • 15,001
  • 18
  • 87
  • 175