我使用动作电缆在Rails中创建套接字api。 然后我使用chrome附加组件发送测试请求。 我收到了这个错误:
成功升级到WebSocket(REQUEST_METHOD:GET, HTTP_CONNECTION:升级,HTTP_UPGRADE:websocket)无法执行 命令来自({“command”=>“message”,“data”=>“{}”, “identifier”=>“{\”channel \“:\”ApiChannel \“}”})[RuntimeError - Unable 找到带标识符的订阅:{“channel”:“ApiChannel”}]: /home/lin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/actioncable-5.1.5/lib/action_cable/connection/subscriptions.rb:76:in
find' | /home/lin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/actioncable-5.1.5/lib/action_cable/connection/subscriptions.rb:53:in
perform_action'| /home/lin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/actioncable-5.1.5/lib/action_cable/connection/subscriptions.rb:17:inexecute_command' | /home/lin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/actioncable-5.1.5/lib/action_cable/connection/base.rb:85:in
dispatch_websocket_message'| /home/lin/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/actioncable-5.1.5/lib/action_cable/server/worker.rb:58:in `block in invoke'
这是我的频道:
class MessagesChannel < ApplicationCable::Channel
def subscribed
stream_from "messages"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
def chat data
Message.create! content: data['content']
ActionCable.server.broadcast 'messages',
message: message.content
end
end
如果您对此有任何经验,请帮我找到解决方案。
答案 0 :(得分:1)
您的错误说:
Unable to find subscription with identifier: {"channel":"ApiChannel"}]
由于你的代码示例显示它被称为MessagesChannel
您是否尝试过更改请求?