【发布时间】:2015-09-25 10:53:45
【问题描述】:
我正在做一个小型 Rails 应用程序。
我正在尝试进行 ajax 调用。
尽管我使用remote: true,但 button_to 正在发出非 ajax 请求。它会将我重定向到此网址http://localhost:3000/lines?product_id=1
<% @products.each do |product| %>
<%= link_to product.name, controller: "store", action: "show", id: product %><br>
<%= button_to "Add to Cart", {controller: "lines", action: "create", product_id: product.id}, method: "POST", remote: true %>
<% end %>
有什么想法吗?
谢谢!
---编辑--- 这是我的 application.js
= require jquery
= require jquery_ujs
//= require turbolinks
//= require_tree .
【问题讨论】:
-
你可以去掉
method- post 是默认的。 -
值得添加您的 application.js,因为这似乎是问题的原因。
-
@Arv - 一些问题,不同的原因。 :) Shadwell 的回答是正确的。 :)
标签: javascript jquery ruby-on-rails ajax button-to