Slide 1

Slide 1 text

real time with rails 5

Slide 2

Slide 2 text

lucas renan

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

guru sorocaba

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

action cable seamlessly integrates websockets with the rest of your rails app

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

yet another chat app

Slide 11

Slide 11 text

!

Slide 12

Slide 12 text

app/channels/rooms_channel.rb class RoomsChannel < ApplicationCable::Channel def subscribed stream_from 'room_sorocaba_channel' # can be dynamic end def unsubscribed # Any cleanup needed when channel is unsubscribed end def send_message(data) ActionCable.server.broadcast('room_sorocaba_channel', data) end end

Slide 13

Slide 13 text

app/assets/javascripts/cable.js (function() { this.App || (this.App = {}); App.cable = ActionCable.createConsumer(); }).call(this);

Slide 14

Slide 14 text

app/assets/javascripts/channels/rooms.js App.rooms = App.cable.subscriptions.create("RoomsChannel", { connected: function() { // Called when the subscription is ready for use on the server }, disconnected: function() { // Called when the subscription has been terminated by the server }, received: function(data) { // Called when there's incoming data on the websocket for this channel }, send_message: function() { return this.perform('send_message'); } });

Slide 15

Slide 15 text

config/routes.rb # Serve websocket cable requests in-process mount ActionCable.server => '/cable'

Slide 16

Slide 16 text

config/cable.yml development: adapter: async test: adapter: async production: adapter: redis url: redis://localhost:6379/1

Slide 17

Slide 17 text

config/environments/production.rb config.action_cable.url = ENV['CABLE_URL'] config.action_cable.allowed_request_origins = ENV['APP_URL']

Slide 18

Slide 18 text

app/views/layouts/application.html.erb <%= action_cable_meta_tag %>

Slide 19

Slide 19 text

https://github.com/lucasrenan/lucas-chat

Slide 20

Slide 20 text

heroku tutorial https://blog.heroku.com/ realtimerailsimplementingwebsocketsinrails5withacti oncable

Slide 21

Slide 21 text

https://lucas-chat-rails5.herokuapp.com/chat

Slide 22

Slide 22 text

thanks :)