All threads / ActionController::UnknownFormat in MessagesController#create

Ask A Question

Notifications

You’re not receiving notifications from this thread.

ActionController::UnknownFormat in MessagesController#create

Rob Sturcke asked in General

Ran into this error in part 4 of the ActionCable group chat. What exactly am I missing? Schema looks fine same with MessagesController.

ActionController::UnknownFormat in MessagesController#create
MessagesController#create is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: []
raise ActionController::UnknownFormat, message

What am I missing?

https://github.com/robSturcke/halibut/commit/4e4f4dce3360344f9326aee202d156591e2d67e3

Hey Rob,

I can't remember exactly, but I know a couple people also had trouble with that one. I believe this was where we setup the form to submit as AJAX and hadn't transitioned it over to sending via the websocket just yet.

Your form is submitting, but it's not sending as a JS request, so your create action crashes looking for an HTML response. What you need is to add remote: true to the form so that will render and execute the create.js.erb file we created.

Basically just change this line: https://github.com/robSturcke/halibut/blob/4e4f4dce3360344f9326aee202d156591e2d67e3/app/views/chatrooms/show.html.erb#L12

to the following:

<%= form_for [@chatroom, Message.new], remote: true do |f| %>

That should do the trick! Your form needs to submit via AJAX request so that the browser doesn't reload the page each time you send a message. That'd be a really poor experience.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 38,311+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    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

    © 2020 GoRails, LLC. All rights reserved.