问题描述
基本上,我无法获得带有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请求吗?我在这上面花费了愚蠢的时间。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)