crowdint / acts_as_shopping_cart

Simple Shopping Cart implementation, Official repo: https://github.com/dabit/acts_as_shopping_cart
MIT License
257 stars 88 forks source link

"button_to 'Button', @shopping_cart.clear" yields error #21

Closed muhammadn closed 10 years ago

muhammadn commented 10 years ago

I am having a bit of a problem with acts_as_shopping_cart.

After writing:

<%=  button_to 'Button', @shopping_cart.clear %>

It spits out the error saying:

Nil location provided. Can't build URI.
dabit commented 10 years ago

Hey @muhammadn

This is not how you would use this.

@shopping_cart.clear is code you would use in a controller action. Your code needs to look something like this:

<%=  button_to 'Button', shopping_cart_path, method: :delete %>

Assuming you specified a route for the delete action on the shopping cart. Then, on that action do something like:

class ShoppingCartController < ApplicationController
  def delete
     @shopping_cart.clear
  end
end