我收到了以下错误
Subscription class not found: "room_channel"
在我的Rails API only项目中,它不包含任何资产/脚本 . 我生成了一个电缆和通道并将其路径安装为
mount ActionCable.server, at: '/cable'
Model:
class Discussion < ApplicationRecord
after_commit { ActionCable.server.broadcast "room_channel", as_json.merge(message: 'test values for ActionCable')}
end
在创建讨论时,它会广播:
[ActionCable]广播到room_channel:{“id”=> 40,“description”=>“new”,“created_at”=>星期四,2017年6月15日09:13:06 UTC 00:00,“updated_at”=>星期四,2017年6月15日09:13:06 UTC 00:00,“avatar_url”=> nil,“full_name”=> nil,“job_title”=> nil,“company”=> nil,“email”=> nil, “msisdn”=> nil,:message =>“ActionCable的测试值”}
在Angular 4客户端应用程序上我使用package for actioncable:
app.component.ts
import { Component } from '@angular/core';
import { Ng2Cable, Broadcaster } from 'ng2-cable';
@Component({
moduleId: module.id,
selector: 'sd-app',
templateUrl: 'app.component.html',
providers:[Ng2Cable, Broadcaster] //or add to main @NgModule
})
export class AppComponent {
constructor(private ng2cable: Ng2Cable,
private broadcaster: Broadcaster) {
this.ng2cable.subscribe('http://localhost:1337/cable', 'room_channel');
this.broadcaster.on<string>('room_channel').subscribe(
message => {
console.log(message);
}
);
}
}