-1

我正在尝试使用 rails 实现像 facebook 或 twitter 这样的新闻流。如何动态添加新帖子。我可以在 rails 中使用 websockets 吗?

4

1 回答 1

1

Rails 因不支持实时 websocket 以及 node.js 之类的东西而臭名昭著,它们实际上是live action在控制器中适应 a :

class MyController < ActionController::Base
  include ActionController::Live

  def stream
    response.headers['Content-Type'] = 'text/event-stream'
    100.times {
      response.stream.write "hello world\n"
      sleep 1
    }
  ensure
    response.stream.close
  end
end

我对此了解不多,因此您应该查看rails API以寻求帮助:)

于 2013-10-14T18:24:49.873 回答