0

Very new to action cable and angular 2. I keep receiving this error, Subscription class not found: "MessagesChannel", when running the rails server. I am using ng2-cable to connect to my rails api.

I am using angular 2 on cordova

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { MessageData } from '../providers/message-data';
import { Ng2Cable, Broadcaster } from 'ng2-cable/js/index';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [ MessageData, Ng2Cable, Broadcaster ]
})
export class AppModule {
  messages: any;
  constructor(private ng2cable: Ng2Cable, private broadcaster:       Broadcaster){
    this.ng2cable.subscribe('http://localhost:3000/cable',   'MessagesChannel');


  }

}

Rails MessagesChannel

class MessagesChannel < ApplicationCable::MessagesChannel
  def subscribed
    stream_from 'allmessages'
  end
end

Any help is appreciated!

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
RickD
  • 79
  • 13

1 Answers1

1

Hope this still helps: Default ActionCable channels inherit from ApplicationCable::Channel, which is defined inside app/channels/application_cable folder. You inherited from ApplicationCable::MessagesChannel. Unless you explicitly defined that parent class, what one would expect to have is the following:

class MessagesChannel < ApplicationCable::Channel
  def subscribed
    stream_from 'allmessages'
  end
end
sivicencio
  • 11
  • 2