我能找到的所有示例都是订阅一个房间,但如果我有A、B和C房间,而我(作为用户)都在这三个房间中,那会怎么样呢?
这是一个带有一个房间http://edgeguides.rubyonrails.org/action_cable_overview.html#client-server-interactions-subscriptions的示例
发布于 2017-01-17 20:14:10
这可能会对link有所帮助,在*.js.erb模板中,你可以动态地创建房间。
<% Chatroom.all.each do |chatroom| %>
App['room' + <%=chatroom.id%>] = App.cable.subscriptions.create({channel: 'MessagesChannel', room: <%=chatroom.id%>}, {
received: function(data) {
$("[data-chatroom='" + this.chatroomId + "']").removeClass('hidden')
return $("[data-chatroom='" + this.chatroomId + "']").append(data.message);
},
setChatroomId: function(chatroomId) {
this.chatroomId = chatroomId
}
});
<% end %>https://stackoverflow.com/questions/38399137
复制相似问题