Rails Action Cable 前端 JS"Uncaught ReferenceError: data is not defined"错误

403 · December 19, 2017 · Last by lithium4010 replied at December 19, 2017 · 2550 hits

Uncaught ReferenceError: data is not defined,一直报这样的错误

rails 版本 5.0.6

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

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end
end

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

  disconnected: ->

  received: (data) ->
    alert (data.message)

application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .

controller

ActionCable.server.broadcast 'room_channel',{message: 'asdfasdf'}

出错情况

刚接触 Action Cable,这个问题出的莫名其妙。。。希望有大佬,可以帮帮我!😵

问题解决

是由于 application.js 中

//= require bootstrap

引起去掉就可以了

写到 function 里面啊

403 closed this topic. 20 Dec 09:23
You need to Sign in before reply, if you don't have an account, please Sign up first.