I'm building an app using Rails & ActionCable, but I keep getting
undefined local variable or method `current_user'
and connect
method never hits
class OrdersChannel < ApplicationCable::Channel
def subscribed
stream_from "market_orders_channel_#{current_user.id}"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
rescue_from ActiveRecord::RecordNotFound do
reject_unauthorized_connection
end
def connect
self.current_user = find_verified_user
end
protected
def find_verified_user
token = Doorkeeper::AccessToken.find_by(token: request.params[:access_token])
reject_unauthorized_connection if token.blank?
Spree::User.find(token.resource_owner_id)
end
end
end
When I add a breakpoint in connection it is never called, and I keep getting error in subscribed
method. How to solve this issue? I'm using ruby 2.5.1 & rails 5.2.0
I've tried all other solutions but none of them works