Reputation: 3
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags "ActionCable","User #{current_user.id}"
end
def find_varified_user
if current_user = env['wardon'].user
current_user
else
reject_unauthorized_connection
end
end
end
end
Upvotes: 0
Views: 1366
Reputation: 341
first, you generate a channel
rails g channel {channel_name} {the action you will send to}
this will generate the channel in "app/channels" folder
then mount the channel in routes.rb
#config/routes.rb
# add this line
mount ActionCable.server => '/cable'
then you subscribe to the channel from your client app and use the method you've created in your channel
you can review this tutorial Create Chat Using Action Cable
but ignore the client-side part
Upvotes: 3