Jer Kehoe

Joined

410 Experience
4 Lessons Completed
0 Questions Solved

Activity

Posted in Group Chat with ActionCable: Part 4 Discussion

Had the same error, running on Rails 5.2, needed to replace form_for with form_with for the message form

<%= form_with model: [@chatroom, Message.new], :html => { :id => 'new_message'} do |f| %>

Also Rails UJS in 5.2 doesn't intercept a submit triggered by javascript, so I needed to use the Rails.fire() method to submit the form in my keypress handler

$(document).on "turbolinks:load", ->
    $("#new_message").on "keypress", (e) ->
        if e && e.keyCode == 13
            e.preventDefault()
            Rails.fire(this, 'submit')
logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.