-1

I'm trying to implement a news-stream like facebook or twitter has using rails . How can i dynamically add new posts . Can i use websockets here in rails ?

  • Yes, you can use websockets. You can also look in to [ActionController::Live with SSE](http://railscasts.com/episodes/401-actioncontroller-live). Be aware of [some of the issues](http://stackoverflow.com/q/18970458/877472) around that, and the [on-going discussions](https://github.com/rails/rails/issues/10989). – Paul Richter Oct 14 '13 at 18:23

1 Answers1

1

Rails is notoriously bad for not supporting live websockets as well as something like node.js, and they're actually adapting with a live action in the controller:

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

I don't know much about it, so you should look on the rails API for help :)

Richard Peck
  • 76,116
  • 9
  • 93
  • 147