Rails 4: Notifications to the user

I am using an action cable to create notifications in my application. The notification area was created based on this guide . The question is: how can I split user notifications? so that notifications are sent to each user individually. I am using rails 4.2.6 withgem 'actioncable'

I also get this error on the route mount ActionCable.server => '/cable'when trying to start the server:

/config/routes.rb:9:in `block in ': uninitialized constant ActionCable (NameError)

and this error when I try to create a chanel

enter image description here

Thank!

+4
source share
1 answer

, Rails 5, , .

, , UserChannel stream_for, :

class UserChannel < ApplicationCable::Channel
  def subscribed
    stream_for current_user
  end
end

, , :

user = User.find(params[:id])
UserChannel.broadcast_to(user, { notification: 'Test message' })
0

Source: https://habr.com/ru/post/1695976/


All Articles