I want to keep different connections to different users just like Node.js with Socket.IO does.
Asked
Active
Viewed 2,805 times
2
-
1Have you watched the Faye Railscast episode? http://railscasts.com/episodes/260-messaging-with-faye – jcm Oct 11 '13 at 16:51
1 Answers
1
You should look at this tutorial.
It's about sending private message to a specific user. So, it's almost the same.
For this, you can make users subscribe to their own channel (for example, /users/user_id)
client = Faye.Client('http://localhost:9292/faye');
client.subscribe('/users/USER_ID', function (data) { something; });
Then, you just have to push data to the user's channel.
<% broadcast '/users/USER_ID' %>
something
<% end %>
The broadcast method comes from this RailsCast that you should watch/read if you haven't already done it yet.

Simon Ninon
- 2,371
- 26
- 43
-
I need to send a notification from Rails Controller Action to a particular user – abhim Oct 11 '13 at 17:18
-
I want to be able to push data to the user channel from a controller action (on receiving a get request from outside)---Simon Ninon? – abhim Oct 11 '13 at 20:30
-
You should look at this [RailsCast](http://railscasts.com/episodes/260-messaging-with-faye) (it seems you didn't) as i said in my answer: it learns you the way to use Faye (diffusing data to a channel after a request to the server). Then, you have to make user subscribe to their own channel. – Simon Ninon Oct 11 '13 at 20:59
-
Instead of USER_ID, I need to replace it with <% current_user.id %>, right? – abhim Oct 11 '13 at 21:09
-
-
I have tried doing it but to no use, is there any way I could debug the flow. – abhim Oct 12 '13 at 07:19