【问题标题】:ActionCable connect method never get calledActionCable 连接方法永远不会被调用
【发布时间】: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

我已经尝试了所有其他解决方案,但没有一个有效

【问题讨论】:

标签: ruby-on-rails actioncable


【解决方案1】:

我已经解决了这个问题,我想在我的 Spree 扩展中定义动作有线电视频道而不是我的主项目,当我将我的代码移动到主项目时它可以工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多