· 1 min read

Screencast: Private Pub für Realtime-Events

Downloads in verschiedenen Formaten:

mp4 mp4 webm ogg

Resourcen:

Gemfile

[ruby] gem ‘private_pub’ [/ruby]

terminal

[bash] bundle rails g private_pub:install rackup private_pub.ru -s thin -E production [/bash]

messages/index.html.erb

[html] <%= subscribe_to “/messages/new” %> [/html]

messages/create.js.erb

[javascript] <% publish_to “/messages/new” do %> $(“#chat”).append(”<%= j render(@message) %>”); <% end %> [/javascript]

messages_controller.rb

[ruby] PrivatePub.publish_to(“/messages/new”, message: @message) [/ruby]

app/assets/javascripts/messages.js.coffee

[javascript] PrivatePub.subscribe “/messages/new”, (data, channel) -> alert data.message.content [/javascript]

Back to Blog