Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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 on rails 操作电缆不工作我必须刷新两个选项卡才能看到消息_Ruby On Rails_Ruby_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails 操作电缆不工作我必须刷新两个选项卡才能看到消息

Ruby on rails 操作电缆不工作我必须刷新两个选项卡才能看到消息,ruby-on-rails,ruby,ruby-on-rails-5,Ruby On Rails,Ruby,Ruby On Rails 5,这是房间代码。咖啡: App.room = App.cable.subscriptions.create "RoomChannel", connected: -> disconnected: -> received: (data) -> $('#messages').append "<p>#{data}</p>" speak: (message) -> @perform 'speak' , messa

这是房间代码。咖啡:

App.room = App.cable.subscriptions.create "RoomChannel",
  connected: -> 
  disconnected: -> 

  received: (data) ->
    $('#messages').append "<p>#{data}</p>"    

  speak: (message) ->
    @perform 'speak' , message: message
房间.咖啡:

$ ->
    $messages = $('messages')
    $messages.scrollTop $messages.prop('scrollHieght')
    $('#message_input').focus()

$(document).on 'keypress','message_input','e'->
    if e.keycode == 13 and e.target.value
    App.room.speak(e.target.value)
    e.target.value = ''
    e.preventDefault()
房间频道:

class RoomChannel < ApplicationCable::Channel
  def subscribed
     stream_from "room_channel"
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end

  def speak(data)
    message.create content: data['message']
  end
end

创建新邮件时,它不会自动加载我浏览器中的所有邮件,直到页面处于“不重新加载”状态。

我也遇到了类似问题。尝试在房间视图中包括cable.coffee/js

<%= javascript_include_tag 'cable', 'data-turbolinks-track': 'reload' %>

谷歌搜索中出现了一个老问题,但有人提到过输入错误吗:

$messages.scrollTop $messages.prop('scrollHieght')
这应该是:

$messages.scrollTop $messages.prop('scrollHeight')

默认应用程序已经重新加载了所有的Java脚本,电缆是其中的一部分。您解决了这个问题吗?
Rails.application.config.assets.precompile += %w( cable.js )
$messages.scrollTop $messages.prop('scrollHieght')
$messages.scrollTop $messages.prop('scrollHeight')