dimanche 11 juin 2017

Subscription class not found 'MyChannel' in ActionCable

I am facing a problem while working with Action Cable, whenever I run my program I receive an error that says 'Subscription Class not found 'ConversationChannel'

and when I try to send a message I get this log

    Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Subscription class not found: "ConversationChannel"
Could not execute command from {"command"=>"message", "identifier"=>"{\"channel\":\"ConversationChannel\"}", "data"=>"{\"message\":[{\"name\":\"conversation_id\",\"value\":\"2\"},{\"name\":\"amitian_id\",\"value\":\"1\"},{\"name\":\"body\",\"value\":\"nmm\"}],\"action\":\"speak\"}"}) [RuntimeError - Unable to find subscription with identifier: {"channel":"ConversationChannel"}]: C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/subscriptions.rb:74:in `find' | C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/subscriptions.rb:53:in `perform_action' | C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/subscriptions.rb:17:in `execute_command' | C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/base.rb:88:in `dispatch_websocket_message' | C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actioncable-5.0.1/lib/action_cable/server/worker.rb:58:in `block in invoke'

I will give my channel.rb and other js files

Here is my ConversationChannel.rb

       class ConversationChannel < ApplicationCable::Channel
      def subscribed
        # stream_from "some_channel"
        stream_from "conversations-#{current_amitian.id}"
      end

      def unsubscribed
        # Any cleanup needed when channel is unsubscribed
        stop_all_streams
      end

      def speak(data)

        message_params = data['message'].each_with_object({}) do |el, hash|
          hash[el.values.first] = el.values.last
        end

        ActionCable.server.broadcast(
          "conversations-#{current_amitian.id}",
          message: message_params
        )
      end

     end

Here is my conversation.js

    App.conversation = App.cable.subscriptions.create("ConversationChannel", {
  connected: function() {

  },
  disconnected: function() {

  },
  received: function(data) {
  console.log(data['message']);
  },
  speak: function(message) {
    return this.perform('speak' , {
    message: message
    });
  }
});

$(document).on('submit', '.new_message', function(e) {
  e.preventDefault();
  var values = $(this).serializeArray();
  App.conversation.speak(values);
  $(this).trigger('reset');
});

This is my connection.rb

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_amitian

    def connect
        self.current_amitian = find_verified_amitian
    end

    protected

    def find_verified_amitian
        if(current_amitian = env['warden'].amitian)
            current_amitian
        else
            reject_unauthorized_connection
        end
    end
  end
end

using the log file given above can anyone tell me why It can't find my conversation_channel.rb file ?

Thank you

Aucun commentaire:

Enregistrer un commentaire