Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 操作电缆不适用于导轨5_Ruby_Websocket_Ruby On Rails 5_Actioncable - Fatal编程技术网

Ruby 操作电缆不适用于导轨5

Ruby 操作电缆不适用于导轨5,ruby,websocket,ruby-on-rails-5,actioncable,Ruby,Websocket,Ruby On Rails 5,Actioncable,我是Rails 5的初学者,我正在尝试在我的应用程序中实现web套接字。我试图复制并运行一个测试应用程序,首先,我发现它不工作,因为它没有发送和接收数据已接收:(数据)->从未被调用。我还注意到,它也从未与我的redis服务器连接(我是用brew安装的)。我正在粘贴下面的所有代码。提前谢谢 //room.coffee App.room = App.cable.subscriptions.create "RoomChannel", connected: -> # Called when

我是Rails 5的初学者,我正在尝试在我的应用程序中实现web套接字。我试图复制并运行一个测试应用程序,首先,我发现它不工作,因为它没有发送和接收数据<代码>已接收:(数据)->从未被调用。我还注意到,它也从未与我的redis服务器连接(我是用brew安装的)。我正在粘贴下面的所有代码。提前谢谢

//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['message'])
speak: (message) -> 
@perform 'speak', message: message
香奈儿酒店

# 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(data)
  ActionCable.server.broadcast "room_channel", message: data['message']
end
end
有线电视,咖啡

# Action Cable provides the framework to deal with WebSockets in Rails.
    # You can generate new channels where WebSocket features live using the rails generate channel command.
    #
    # Turn on the cable connection by removing the comments after the require statements (and ensure it's also on in config/routes.rb).
    #
    #= require action_cable
    #= require_self
    #= require_tree ./channels
    #
    @App ||= {}
    App.cable = ActionCable.createConsumer()

您可以尝试在不使用Redis的情况下使用Action Cable(因为Action Cable并不严格要求使用Redis):

但这可能不是你问题的根源。你的
房间。咖啡
缺少一些
说话
呼叫代码。添加到
room.coffee
类似的内容:

$ ->
  $('#send_form').submit (event)->
    App.room.speak event.currentTarget['message'].value
    event.currentTarget['message'].value = ""
    event.preventDefault()
    false
以下是一个模板:

<div class="jumbotron">
  <form id="send_form">
    <label>Message:</label>
    <input id="message" type="text" data-behavior="room_speaker">
    <br> 
    <input type="submit" data-behavior="room_speaker">
  </form>
</div>

信息:


尝试设置
gem'pg'
而不是
gem'sqlite3'
(和bundle安装)另请参见:我会尝试,但是设置'pg'而不是'sqlite3'1 2的原因是什么
development:
  adapter: async

test:
  adapter: async

production:
  adapter: redis
  url: redis://localhost:6379/1
$ ->
  $('#send_form').submit (event)->
    App.room.speak event.currentTarget['message'].value
    event.currentTarget['message'].value = ""
    event.preventDefault()
    false
<div class="jumbotron">
  <form id="send_form">
    <label>Message:</label>
    <input id="message" type="text" data-behavior="room_speaker">
    <br> 
    <input type="submit" data-behavior="room_speaker">
  </form>
</div>