Skip to main content

ActionController::UnknownFormat in MessagesController#create

General • Asked by Rob Sturcke

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.




Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.