【问题标题】:'button_to' gives me an ugly URL!'button_to' 给了我一个丑陋的 URL!
【发布时间】:2010-04-28 04:59:13
【问题描述】:

我正在尝试让“添加到购物车”按钮起作用。当我使用 <%= button_to "Add to Cart", :acton => "add_to_cart", :id => @product %> 然后单击按钮时,我得到一个将操作放在 ID 之后的 URL,如下所示:http://localhost:3000/store/show/1?acton=add_to_cart 购物车页面未加载。

我需要一个如下所示的 URL:http://localhost:3000/store/add_to_cart/1。如果我不使用“button_to”,我可以获得该结果(并且购物车可以工作):

<% form_for @product, :url => {:action => "add_to_cart", :id => @product} do |f| %>
  <p><%= f.submit 'Add to Cart' %></p>
<% end %>

但是,到底是什么?为什么我不能使用button_to

【问题讨论】:

  • 也许这只是一个错字?如果您的实际代码还显示:acton 而不是:action,这可能是原因。 ;-)

标签: ruby-on-rails ruby forms helpers


【解决方案1】:

在您的 button_to 中,您应该使用 action 而不是 acton

喜欢

<%= button_to "Add to Cart", :action => "add_to_cart", :id => @product %>

【讨论】:

  • 感谢大家的时间。错字的解释是苦乐参半。我盯着它看了好一个小时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多