0
votes

I create an socket api in Rails by using action cable. Then I use chrome add-on to send the request for testing. I got this error:

Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) Could not execute command from ({"command"=>"message", "data"=>"{}", "identifier"=>"{\"channel\":\"ApiChannel\"}"}) [RuntimeError - Unable to find subscription with identifier: {"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:in execute_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:indispatch_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'

Here is my channel:

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

If you have any experience with this, please help me find a solution.

1

1 Answers

1
votes

Your error says:

Unable to find subscription with identifier: {"channel":"ApiChannel"}]

Which makes since, since your code sample shows that it's called MessagesChannel

Have you tried changing your request?