Moving the channel functionality to show

The next step in polishing up our application is moving our channel logic to instead be poll-specific instead of all sitting in the lobby. Open up show.html.eex and change the template to include the WebSocket-specific code that used to live in index.html.eex. We'll need to modify it slightly as well since we'll need to have a way to tell JavaScript what poll ID it needs to use to find the right topic:

<i id="enable-polls-channel" data-poll-id="<%= @poll.id %>"></i><button id="polls-ping" class="btn btn-primary">Ping Websocket</button>

We'll also need to open up socket.js and change the code to start using this new code. Modify the old if statement that checked if polls were enabled for that page to ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.