基本上我无法获得remote: true
作为 xhr 请求提交的表单。
html.erb
自从我使用基于和js.erb
基础的前端以来已经有很长时间了,所以我可能在这里做一些愚蠢的事情
使用 Ruby 2.5.7 和 rails 4.2.11,我正在使用gem 'jquery-rails'
.
我的application.js
包含:
//= require jquery
//= require jquery_ujs
//= require jquery-ui.js
//= require safari_form_submission_workaround.js
我们的应用程序中有许多表单form_tag
用于remote: true
发出 ajax 请求,但特定的表单不起作用。它发送带有标头的请求,Content-Type text/html
然后抛出错误,因为它找不到相应的模板,因为它不是在寻找带有js.erb
后缀的东西
生成表单的 html 是:
<%= form_tag waitlist_item_creator_path, id: 'item_creator', remote: true do %>
并且呈现的html是
<form id="item_creator" action="/waitlist_item_creator" accept-charset="UTF-8" data-remote="true" method="post">
我已经验证了 jQuery$
在这种情况下是可用的。具体错误是: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:
这似乎表明它正在根据请求标头寻找错误的格式。
关于这里可能出了什么问题或者我如何更聪明地调试它的任何想法?还有其他方法可以强制它作为 js 请求提交吗?我在这上面花了很多时间。