ActionCable: one channel per user

I am working on notifications for my rails application. There is a user model and controller, and the Like model associated with the user with the user has many Likes associations.

The idea is that if a user likes another user's profile, the owner of the profile will receive a live notification.

This is my application for understanding ActionCable. I learned the api cable , pub-sub was new to me. I was able to successfully communicate through one channel, and also successfully used authorization . But, nevertheless, I do not understand how to use one channel for each user (dynamically created channel) so that the message sent to one user does not go to another user.

Is it possible to use a dynamic channel?

Or are there other ways when one channel meets all the needs of users.

+4
source share
1 answer

The solution was actually simple, but some of the new terms introduced in ActionCable made it confusing. By the way, this is how I decided it.

I used one channel, but several streams for different users. Here's an ActionCable link that clearly shows a very similar scenario. I looked through the documentation before, but for some reason I did not understand it at first sight.

Sorry for the lack of direct code, I think the documentation will fully explain it.

+6
source

All Articles