【问题标题】:ActionCable channel doesn't connect unless page is reloaded除非重新加载页面,否则 ActionCable 频道不会连接
【发布时间】:2019-02-13 01:05:49
【问题描述】:

如果我手动刷新页面,我的电缆效果很好,但如果我导航到它,它就永远不会开始流式传输。

如果工作正常,我会在 Rails 控制台中看到:

ChecklistPdfChannel is transmitting the subscription confirmation
ChecklistPdfChannel is streaming from checklist_pdf_2-5a-ntiasohen-gattopuin

这是咖啡脚本:

document.addEventListener 'turbolinks:load', ->
  if !App.presence
    App.presence = App.cable.subscriptions.create({
      channel: 'ChecklistPdfChannel',
      issueable_id: window.location.pathname.split('/').splice(2,1).toString()
    },
      connected: ->
      disconnected: ->
      received: (data) ->
        console.log(data)
        $('#pdf_status').html "#{data.html}"
  )
return

我尝试了以下方法:

  • 添加元标记:<meta name="turbolinks-cache-control" content="no-cache">
  • 在布局中的资产调用中添加了'data-turbolinks-track': 'reload'

在开发和暂存/生产 (Heroku) 中的行为是相同的。

Rails 5.2.2、ActionCable 5.2.2、Turbolinks 5.2.0

【问题讨论】:

  • data-no-turbolink(如<%= link_to('Giraffe', @giraffe, 'data-no-turbolink' => true) %>)添加到使用ActionCable 导航到页面的链接中。
  • 不幸的是,即使使用data-no-turbolink,这种情况仍然存在。我必须重新加载页面才能启用有线频道。

标签: ruby-on-rails-5 turbolinks actioncable


【解决方案1】:

所以我能够让它工作的唯一方法是在我需要激活电缆的页面上添加这个元标记:

<meta name="turbolinks-visit-control" content="reload">

【讨论】:

    猜你喜欢
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-21
    • 2020-12-28
    • 2014-06-06
    • 2021-12-30
    • 2019-07-10
    相关资源
    最近更新 更多