Ruby and Server-sent events

by acdesouza

GitHub Readme.md

Rails 4 ActionController::Live and HTML5 Server Sent Events

Using Browser feature SSE to retrieve changes on a Rails4 application stream

Steps

  1. rails 4.0.0 new
  2. Add Puma server, witch support Server Sent Events: http://puma.io/
  3. Allow concurrency on development enviroment
  4. Add helper to write on stream
  5. Scaffold a model to use on live test
  6. Add stream capability to UsersController, using ActionController::Live
  7. Provide stream, of last user changed, on UsersController and consumes using HTML5 Server Sent Event

How to see it working

Easy way

  1. Deploy
  2. heroku run rake db:migrate

Local way

  1. git clone https://github.com/acdesouza/rails-and-server-sent-events.git .
  2. bundle install
  3. bundle exec rake db:create db:migrate
  4. bundle exec rails s

And then...

  1. On Browser 1: User watch stream
  2. On Browser 2: User watch stream
  3. On Browser 3: User list
  4. Redimension browser's windows to make browser visible
  5. On Browser 3: Create an user
  6. On Browser 1,2: See they receiving the update

Fonts