rails でchatアプリを作るための練習をしています。channelのspeakメソッドでdbに保存して送るところで、
Could not execute command from ({"command"=>"message", "identifier"=>"{"channel":"RoomChannel"}", "data"=>"{"message":"aaaaaaaa","action":"speak"}"}) [NameError - uninitialized constant RoomChannel::Messsage]
と出てしまいます。(成功したらアラートが表示されるはずです
コード
。)
NameErrorとありますが、手本を見ながらしていて、手本と同じように入力しているはずで、どのように直したらいいのか、また違うことが原因なのか分かりません。どなたか、ご教授ください。お願いします。
ruby
1class RoomChannel < ApplicationCable::Channel 2 def subscribed 3 4 end 5 6 def unsubscribed 7 # Any cleanup needed when channel is unsubscribed 8 end 9 10 def speak(data) 11 Messsage.create!(content: data['message']) 12 ActionCable.server.broadcast 'room_channel' ,data['message'] 13 end 14end 15
ruby
1App.room = App.cable.subscriptions.create("RoomChannel", { 2 connected: function() { 3 console.log('connectedddd') 4 }, 5 6 disconnected: function() { 7 // Called when the subscription has been terminated by the server 8 }, 9 10 received: function(data) { 11 alert(data) 12 }, 13 14 speak: function() { 15 return this.perform('speak',{message:"aaaaaaaa"}); 16 } 17}); 18
log
1Started GET "/cable" for ::1 at 2020-01-29 20:15:26 +0900 2Started GET "/cable/" [WebSocket] for ::1 at 2020-01-29 20:15:26 +0900 3Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) 4Started GET "/cable" for 127.0.0.1 at 2020-01-29 20:15:27 +0900 5Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2020-01-29 20:15:27 +0900 6Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) 7RoomChannel is transmitting the subscription confirmation 8RoomChannel is transmitting the subscription confirmation 9RoomChannel#speak({"message"=>"aaaaaaaa"}) 10Could not execute command from ({"command"=>"message", "identifier"=>"{\"channel\":\"RoomChannel\"}", "data"=>"{\"message\":\"aaaaaaaa\",\"action\":\"speak\"}"}) [NameError - uninitialized constant RoomChannel::Messsage]: C:/Users/LS150/Desktop/chat_app2/app/channels/room_channel.rb:11:in `speak' | C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/actioncable-5.2.4.1/lib/action_cable/channel/base.rb:266:in `public_send' | C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/actioncable-5.2.4.1/lib/action_cable/channel/base.rb:266:in `dispatch_action' | C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/actioncable-5.2.4.1/lib/action_cable/channel/base.rb:168:in `block in perform_action' | C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/notifications.rb:170:in `instrument' 11
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。