###前提・実現したいこと
製作中のアプリにActionCableでリアルタイム通信を実装したいです。
###発生している問題・エラーメッセージ
単なるJavaScriptのエラーだと思うんですが、、、
RoomChannel#speak({"message"=>"Hello world"}) Could not execute command from {"command"=>"message", "identifier"=>"{\"channel\":\"RoomChannel\"}", "data"=>"{\"message\":\"Hello world\",\"action\":\"speak\"}"}) [NameError - undefined local variable or method `message' for #<RoomChannel:0x000000055f4b50>]: /home/ubuntu/workspace/app/channels/room_channel.rb:12:in `speak' | /usr/local/rvm/gems/ruby-2.3.0/gems/actioncable-5.0.0/lib/action_cable/channel/base.rb:260:in `public_send' | /usr/local/rvm/gems/ruby-2.3.0/gems/actioncable-5.0.0/lib/action_cable/channel/base.rb:260:in `dispatch_action' | /usr/local/rvm/gems/ruby-2.3.0/gems/actioncable-5.0.0/lib/action_cable/channel/base.rb:165:in `block in perform_action' | /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0/lib/active_support/notifications.rb:166:in `instrument'
###該当のソースコード
【room_channel.rb】
# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. class RoomChannel < ApplicationCable::Channel def subscribed stream_from "room_channel" end def unsubscribed # Any cleanup needed when channel is unsubscribed end def speak ActionCable.server.broadcast 'room_channel', message: data['message'] end end
【rooms.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['message'] speak: (message) -> @perform 'speak', message: message
###補足情報(言語/FW/ツール等のバージョンなど)
この部分を参考にしてます。アラートが僕の場合なりません。
ご経験ある方、お力を貸してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。