【问题标题】:Rails 5 message app wan't show chatroom messages unless reloadedRails 5 消息应用程序不会显示聊天室消息,除非重新加载
【发布时间】:2020-04-19 12:21:13
【问题描述】:

我正在做关于 message_me 应用程序的教程,但我编写并点击 enterwan 的消息不会显示在索引聊天室页面上,除非我重新加载页面。我已经尝试使用两个浏览器 Firefox 和 Chromium,两个控制台都在同一文件和同一行中向我显示错误:app/assets/javascripts/channels/chatroom.coffee: }, $('#message-container').append(data.mod_message), scroll_bottom());

ReferenceError: 数据未定义

这是我的应用程序:https://github.com/Citizen1/message_me

【问题讨论】:

  • 您是否在app/assets/javascripts/channels/chatroom.coffeereceived 方法中尝试过console.log(data) 以确保您正在取回数据?
  • 我已经尝试过,我正在取回数据。但我也在我的 Rails 服务器中看到了事务结束时的这条消息:No template found for MessagesController#create, rendering head :no_content。然后如果重新加载页面我可以看到消息
  • 你的表单上有remote: true吗?
  • 是的,我在 app/views/chatroom/index.html.erb 中有,你可以在我的 github repo 中看到它

标签: ruby-on-rails-5 actioncable


【解决方案1】:

问题出在您的 chatroom.coffee 文件中。你必须缩进received: (data)下的行:

received: (data) ->
  $('#message-container').append data.mod_message
  scroll_bottom()

CoffeeScript 有严格的indenting 准则。

【讨论】:

  • 它现在可以工作了,我不敢相信解决方案是如此平庸!
猜你喜欢
  • 2016-08-29
  • 1970-01-01
  • 2017-06-01
  • 2020-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-06
  • 2019-08-24
相关资源
最近更新 更多