I am working on Hartl's tutorial Learn Enough Action Cable, and I'm stuck on section 4.1. I copied and pasted the code from the tutorial just to be sure, and the pop up window with data.content still wont come up.
Messages Controller:
.
.
def create
message = current_user.messages.build(message_params)
if message.save
ActionCable.server.broadcast 'room_channel',
content: message.content,
username: message.user.username
end
end
room_channel.rb:
class RoomChannel < ApplicationCable::Channel
def subscribed
stream_from "room_channel"
end
def unsubscribed
end
end
routes.rb:
Rails.application.routes.draw do
root 'messages#index'
resources :users
resources :messages
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
mount ActionCable.server, at: '/cable'
end
room.coffee:
App.room = App.cable.subscriptions.create "RoomChannel",
connected: ->
# Called when the subscription is ready for use on the server
disconnected: ->
# Called when the subscription has been terminated by the server
received: (data) ->
alert(data.content)
Every other part of the tutorial worked fine with pop-up windows coming up for javascript alerts. In my server logs it says:
Started GET "/cable" for 127.0.0.1 at 2017-03-26 13:59:12 -0400
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2017-03-26 13:59:12 -0400
Successfully upgraded to WebSocket (REQUEST_METHOD: GET,HTTP_CONNECTION: keep-alive, Upgrade, HTTP_UPGRADE: websocket)
RoomChannel is transmitting the subscription confirmation
RoomChannel is streaming from room_channel
Finished "/cable/" [WebSocket] for 127.0.0.1 at 2017-03-26 14:06:26 -0400
RoomChannel stopped streaming from room_channel
Started GET "/messages" for 127.0.0.1 at 2017-03-26 14:06:26 -0400
Processing by MessagesController#index as HTML
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
Message Load (0.2ms) SELECT "messages".* FROM "messages" ORDER BY "messages"."created_at" DESC LIMIT ? [["LIMIT", 50]]
Rendering messages/index.html.erb within layouts/application
Rendered messages/_messages.html.erb (0.6ms)
Rendered messages/_message_form.html.erb (2.0ms)
Rendered messages/index.html.erb within layouts/application (4.5ms)
Rendered layouts/_logo.html.erb (0.4ms)
Rendered layouts/_header.html.erb (2.0ms)
Completed 200 OK in 71ms (Views: 36.4ms | ActiveRecord: 1.5ms)