views:

142

answers:

1

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_for @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?

+2  A: 

in your button_to you should use action instead of acton

like

<%= button_to "Add to Cart", :action => "add_to_cart", :id => @product %>
Salil
thanks guys for the time. the typo explanation is bittersweet. I stared at that for a good hour.
Jake