这是一个非常奇怪的故障。我的网站只是让我在首次加载页面时发送消息,如果我通过Chrome浏览器控制台通过App.room.speak创建消息,则消息发送和恢复工作正常("您好&# 34)
下面是.coffee。它来自教程和本教程的C& P没有问题,所以我想知道为什么会这样。
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) ->
$('#messages').append('<br>'+data['message'])
speak: (message) ->
@perform 'speak', message: message
$(document).on 'keypress', (event) ->
if event.keyCode is 13# return = send
App.room.speak event.target.value
event.target.value = ''
event.preventDefault()
的Gemfile:
source 'https://rubygems.org'
ruby "2.3.0"
gem 'rails', '5.0.0.beta3'
gem 'bootstrap-sass'
gem 'sass-rails'
gem 'uglifier'
gem 'faker'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
gem 'puma', '3.4.0'
gem 'carrierwave'
gem 'bootstrap-will_paginate'
gem 'execjs'
gem 'actioncable', '~> 5.0.0.beta3'
gem 'sdoc', group: :doc
# Security
gem 'bcrypt'
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
# gem 'web-console'
gem 'spring'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
最后是我的application.html.erb文件
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(@title) %></title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= action_cable_meta_tag %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
</head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Body -->
<body>
<!-- Navbar -->
<%= render 'layouts/navbar' %>
<!-- Flash -->
<% flash.each do |message_type, message| %>
<div class="slideanim2 fadeout alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<!-- Main Container -->
<% if !@container_mode.nil? && @container_mode == "FLUID" %>
<div class = "container-fluid">
<% else %>
<div class = "container">
<% end %>
<!-- Render main page content -->
<%= yield %>
<!-- Render Debug -->
<% # debug(params) if Rails.env.development? %>
</div>
</body>
<!-- Navbar -->
<%= render 'layouts/footer' %>
</html>
<!-- JQUERY STUFF -->
<script>
$(document).ready(function(){
setTimeout(function(){ $('.fadeout').fadeTo(1000, 0) }, 4000);
$(".slideanim2").each(function(){
var pos = $(this).offset().top;
$(this).addClass("slide");
});
$(window).scroll(function() {
$(".slideanim").each(function(){
var pos = $(this).offset().top;
var winTop = $(window).scrollTop();
if (pos < winTop + 600) {
$(this).addClass("slide");
}
});
});
})
</script>
请帮忙!