我正在尝试Rails 5的动作电缆功能。
如果我尝试使用rake
任务进行广播,则表示我没有收到消息。
有谁看到这个问题?正在建立联系。
非常感谢你。
channel.rb
module ApplicationCable
class Channel < ActionCable::Channel::Base
def connect
self.current_user = find_verified_user
end
private
def find_verified_user
if current_user
return current_user
else
reject_unauthorized_connection
end
end
end
end
FileStatusChannel.rb
class FileStatusChannel < ApplicationCable::Channel
def subscribed
matching_job = MatchingJob.find_by_uuid(params[:file_uuid])
stream_for matching_job
end
end
的Javascript
<script>
// Action Cable
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
}).call(this);
App.cable.subscriptions.create({
channel: "FileStatusChannel",
file_uuid: "18e01f4e-1d20-4905-b713-9ddc7adc4ae0",
received: function(data) {
console.log(data);
}
});
</script>
佣金任务
matching_job = MatchingJob.find_by_uuid("18e01f4e-1d20-4905-b713-9ddc7adc4ae0")
FileStatusChannel.broadcast_to(matching_job, {hello: "test"})
Rails记录
FileStatusChannel is transmitting the subscription confirmation
FileStatusChannel is streaming from file_status:Z2lkOi8vcmV0YWlscXVhbnQtc3RhYmxlL01hdGNoaW5nSm9iLzc