Jake
Jake

Reputation: 31

'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_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?

Upvotes: 0

Views: 885

Answers (1)

Salil
Salil

Reputation: 47472

in your button_to you should use action instead of acton

like

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

Upvotes: 4

Related Questions