Mike

Joined

10 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Group Chat with ActionCable: Part 4 Discussion

Since rails 5.2 the remote: true doesn't really work anymore for the form_for when you are trying to submit a new chat message in JS. I found that no matter how I tried to get it to answer with remote: true as JS it would always post it as html. The answer for rails 5.2+ is to use form_with as form_for is being depreciated. Also by default form_with sends all submits as JS, so we don't use remote: true.

In your show.html.erb, change the form_for line to this:
<%= form_with model: [@chatroom, Message.new], :html => { :id => 'chatroom_form' } do |f| %>

In your create.js.erb change the reset line to this:
$("#chatroom_form")[0].reset()

And if you are still doing the area thing (I didn't like that style personally) you need to change the keypress line to this:
  $("#message_body").on "keypress", (e) ->