【发布时间】:2019-08-08 00:04:43
【问题描述】:
我正在使用 Rails 和 ActionCable 构建一个应用程序,但我不断得到 p>
未定义的局部变量或方法`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
我已经尝试了所有其他解决方案,但没有一个有效
【问题讨论】: