我意识到这是一个不具体的问题,但我不确定我的问题出在哪里,所以请耐心等待。
我正在尝试在 Sprockets 上的 Rails 6.1.4.1 中设置 Action Cable(无 webpacker 集成)。设置基本频道后,我没有得到任何结果;而且也没有错误或任何需要调试的东西,所以我真的不确定我的问题出在哪里。
以下是集成情况:
# config/cable.yml
development:
adapter: async
# channels/notification_channel.rb
class NotificationChannel < ApplicationCable::Channel
def subscribed
stream_from "notification_channel"
end
# app/javascript/channels/notification_channel.js
import consumer from "./consumer"
consumer.subscriptions.create("NotificationChannel", {
connected() {
console.log("Connected to notification channel...");
},
disconnected() {
},
received(data) {
},
notify: function() {
return this.perform('notify');
}
});
# app/javascript/channels/consumer.js
import { createConsumer } from "@rails/actioncable"
export default createConsumer()
# app/javascript/channels/index.js
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
在服务器启动或页面加载时,服务器日志中没有活动
/cable
通道的指示,并且 Web 控制台日志中没有输出。 App.notification
也未定义。再说一遍,客户端或服务器端都没有错误。
有谁知道这种集成是否应该与链轮正常工作?或者这只是一个配置问题?
您找到解决这个问题的方法了吗,我也面临这个问题。