button_to with remote: :true 最终重定向

button_to with remote: :true ends up redirecting

我正在尝试为表单创建一个按钮,允许用户在没有 redirecting/reloading 或其他任何东西的情况下保存输入的数据。

我已将 button_to 添加到我的部分表单中,如下所示:

<%= button_to "Update", incorporation_path(@incorporation), method: :post, remote: true %>

这确实保存了数据,但提交了带有重定向和所有的表单。

在更新控制器方法中添加 render :nothing => true 后,当我单击该按钮时,我看到的只是一个空白页面。这特别令人惊讶,因为我认为 remote: true 行会阻止这种情况。

可能有什么问题?

如有任何想法,我们将不胜感激

更新

你说的是表格!您是否在 form_for 上设置了 remote: true?因为这就是您异步提交表单的方式。

原回答

remote: trueUnobtrusive scripting adapter for jQuery 的一部分。顾名思义,这种方法是 unobtrusice,如果停用 JS 或未加载库,则该方法将不起作用。因此,请确保您的脚本文件中包含以下行:

//= require jquery
//= require jquery_ujs