class NoteChannel < ApplicationCable::Channel
def save_note(data)
note = current_user.notes.find(data[:id])
note.content = data[:content]
note.save!
end
end
收到消息并正确填充数据参数。但是,对note
的更改不会保留在db中。我误解了ActionCable吗?
我无法通过ActionCable访问存储在MySQL数据库中的ActiveRecord模型吗?
答案 0 :(得分:1)
好的结果是代码一般都没问题。我在本地使用Puma作为Web服务器,并且不会像rails s
那样在控制台中显示错误消息。
相反,我不得不拖尾开发日志来查看错误:
tail -f log/development.log
事实证明,这种情况下的错误是404.我本应该以字符串而不是符号的形式访问哈希键:
note = current_user.notes.find(data["id"])