我創建了一個ruby應用程序,我試圖實現操作電纜,當用戶發佈帖子時,我想要爲所有用戶更新帖子索引。在我的頻道/ posts.js我有:ActionCable沒有更新頁面
App.posts = App.cable.subscriptions.create("PostsChannel", {
connected: function() {
// Called when the subscription is ready for use on the server
},
disconnected: function() {
// Called when the subscription has been terminated by the server
},
received: function(data) {
// Called when there's incoming data on the websocket for this channel
console.log(data)
$('#list').html("<%= escape_javascript render('list') %>")
}
});
在PostRelayJob.rb
我:
class PostRelayJob < ApplicationJob
queue_as :default
def perform(post)
ActionCable.server.broadcast "posts",
post: PostsController.render(list)
# Do something later
end
end
和型號/ post.rb:
after_commit { PostRelayJob.perform_later(self) }
當我添加我在服務器控制檯發帖:
[ActiveJob] [PostRelayJob] [57126ec7-b091-48fc-91aa-2f940caa9421] Performing PostRelayJob from Async(default) with arguments: #<GlobalID:0x00000003aa10d8 @uri=#<URI::GID gid://today-i-have2/Post/15>>
[ActiveJob] Enqueued PostRelayJob (Job ID: 57126ec7-b091-48fc-91aa-2f940caa9421) to Async(default) with arguments: #<GlobalID:0x000000037af000 @uri=#<URI::GID gid://today-i-have2/Post/15>>
[ActiveJob] [PostRelayJob] [57126ec7-b091-48fc-91aa-2f940caa9421] Performed PostRelayJob from Async(default) in 3.66ms
Rendering posts/create.js.erb
Rendered posts/_list.html.erb (7.5ms)
Rendered posts/create.js.erb (9.0ms)
Howe在其他瀏覽器的帖子沒有更新,我很新的軌道,所以任何幫助將不勝感激。