我正在Ruby on Rails(v5.0.0)网站上构建聊天功能。我有它finnaly工作unteal我运行捆绑exec rake资产:预编译推动它生产。
我似乎无法重新开始工作!它非常愚蠢......
问题
看起来文件已经不再加载,没有一个脚本在生产或开发上运行。 现在,当您输入评论时,您会收到错误,因为没有coffeeScript接管您的请求。
路由
mount ActionCable.server => '/cable'
application.hml.haml
= action_cable_meta_tag
的application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require cable.coffee
//= require jquery.turbolinks
//= require script.js
//= require bootstrap-sprockets
//= require cable
//= require metronome.js
//= require private_pub
//= require sticky.js
//= require waveform.js
//= require waveform.extensions.js
//= require timeline.js
//= require turbolinks
//= require_self
//= require_tree .
//= require serviceworker-companion
//= require addtohomescreen.js
//= require dragend.js
cable.coo
# app/assets/javascripts/cable.coffee
# 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()
/channels/index.coffee
App.cable = ActionCable.createConsumer("/cable")
/channels/rooms.coffee
jQuery(document).on 'turbolinks:load', ->
messages = $('#messages')
if $('#messages').length > 0
App.global_chat = App.cable.subscriptions.create {
channel: "ChatRoomsChannel"
},
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) ->
$('#messages_' + data['chat_room_id']).prepend($(data['message']).fadeIn(400))
$(document.getElementById('notification').src = 'https://www.jammify.com/metronome_low.mp3';notification.play());
send_message: (message, chat_room_id, user_id, receiver_id) ->
@perform 'send_message', message: message, chat_room_id: chat_room_id, user_id: user_id, receiver_id: receiver_id
$('.new_message').submit (e) ->
$this = $(this)
textarea = $this.find('#message_body')
chat_room_id = $this.find('#message_chat_room_id')
if $.trim(textarea.val()).length > 1
App.global_chat.send_message textarea.val(), chat_room_id.val(), $('#messages_' + chat_room_id.val()).data('user-id'), $('#messages_' + chat_room_id.val()).data('receiver-id')
textarea.val('')
e.preventDefault()
return false
你们还需要其他人吗? 它看起来像整个rooms.coffee完全没有加载。