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

Reply

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.

Reply

Thanks so much!

Reply

Anytime! 🍻

Reply
Join the discussion
Create an account Log in

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

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

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