'button_to' gives me an ugly URL!
Im trying to get an 'add to cart' button to work. When I use <%= button_to "Add to Cart", :acton => "add_to_cart", :id => @product %>
and then click the button, I get a URL that puts the action after the ID, like this: http://localhost:3000/store/show/1?acton=add_to_cart
The cart page does not load.
What I need is a URL that looks like this: http://localhost:3000/store/add_to_cart/1
. I can get that result (and the cart to work) if I don't use 'button_to':
<% form_开发者_如何学Cfor @product, :url => {:action => "add_to_cart", :id => @product} do |f| %>
<p><%= f.submit 'Add to Cart' %></p>
<% end %>
But, what the heck? Why can't I use button_to
?
in your button_to you should use action instead of acton
like
<%= button_to "Add to Cart", :action => "add_to_cart", :id => @product %>
精彩评论