ActionCable 连接方法永远不会被调用
ActionCable connect method never get called
我正在使用 Rails 和 ActionCable 构建应用程序,但我不断收到
undefined local variable or method `current_user'
和connect
方法永远不会命中
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
当我在连接中添加断点时,它永远不会被调用,而且我在 subscribed
方法中不断出错。如何解决这个问题?我正在使用 ruby 2.5.1 & rails 5.2.0
我已经尝试了所有其他解决方案,但 none 有效
我已经解决了这个问题,我想在我的 Spree
扩展中定义动作有线频道,而不是在我的主项目中,当我将我的代码移动到主项目时它可以工作
我正在使用 Rails 和 ActionCable 构建应用程序,但我不断收到
undefined local variable or method `current_user'
和connect
方法永远不会命中
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
当我在连接中添加断点时,它永远不会被调用,而且我在 subscribed
方法中不断出错。如何解决这个问题?我正在使用 ruby 2.5.1 & rails 5.2.0
我已经尝试了所有其他解决方案,但 none 有效
我已经解决了这个问题,我想在我的 Spree
扩展中定义动作有线频道,而不是在我的主项目中,当我将我的代码移动到主项目时它可以工作