A single `remote: true` form tag will not generate requests as type: `js` in my rails app

489 Views Asked by At

Basically I can't get a form with remote: true to submit as an xhr request.

It's been a long time since I've worked with a html.erb and js.erb based front end so I'm probably doing something dumb here

Using Ruby 2.5.7 and rails 4.2.11 and I'm using gem 'jquery-rails'.

My application.js contains:

//= require jquery
//= require jquery_ujs
//= require jquery-ui.js
//= require safari_form_submission_workaround.js

We have many forms in our app that use form_tag with remote: true to make an ajax request but a specific one will not work. It sends the request with the header Content-Type text/html and then throws an error because it can't find a corresponding template because it is not looking for something with a js.erb suffix

The html that generates the form is:

 <%= form_tag waitlist_item_creator_path, id: 'item_creator', remote: true do %>

and the rendered html is

<form id="item_creator" action="/waitlist_item_creator" accept-charset="UTF-8" data-remote="true" method="post"> 

I have verified that the jQuery $ is available in this context. The specific error is: ActionView::MissingTemplate - Missing template order_items/create_waitlist_line_item, application/create_waitlist_line_item with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}. Searched in: which seems to indicate it is looking for the wrong format based on the request header.

Any thoughts on what could be going wrong here or how I could be smarter about debugging it? Any other way to force this to submit as a js request? I have spent a stupid amount of time on this.

0

There are 0 best solutions below