Javascript RubyonRails onError方法中的事件源实时流媒体

Javascript RubyonRails onError方法中的事件源实时流媒体,javascript,ruby-on-rails,ruby-on-rails-4,server-sent-events,Javascript,Ruby On Rails,Ruby On Rails 4,Server Sent Events,我正在尝试使用EventWourceAPI和ActionController live实现基本的Rails4代码。一切正常,但我无法联系到事件侦听器 控制器代码: class HomeController < ApplicationController include ActionController::Live def tester response.headers["Content-Type"] = "text/event

我正在尝试使用EventWourceAPI和ActionController live实现基本的Rails4代码。一切正常,但我无法联系到事件侦听器

控制器代码:

  class HomeController < ApplicationController
            include ActionController::Live
     def tester 
            response.headers["Content-Type"] = "text/event-stream"
            3.times do |n|
            response.stream.write "message: hellow world! \n\n"
            sleep 2
    end
end
当我重新加载页面时,我的控制台输出是“打开状态”&然后是“错误状态”。事件侦听器代码未显示

  • 当我卷起页面时,显示“消息:Hellow world!”

  • 我在发展中改变了

    config.cache\u classes=true

    config.eager\u load=true

  • 我的浏览器是chrome和firefox的最新版本,所以没有问题


  • 我在哪里失踪?请给我一些建议

    服务器发送事件的事件格式为

    "data: message text\n\n"
    
    因此,在您的情况下,应该是这样的:

    response.stream.write "data: hello world! \n\n"
    

    查看参考资料。

    是的,没错。。我遗漏的不是“数据:”,而是“消息:”,我的意思是客户端发送的不是服务器想要的
    response.stream.write "data: hello world! \n\n"