Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
muhammadn opened this issue Jul 23, 2014 · 1 comment
Closed

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

muhammadn opened this issue Jul 23, 2014 · 1 comment

Comments

@muhammadn
Copy link

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
Copy link
Contributor

dabit commented Jul 28, 2014

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

@dabit dabit closed this as completed Jul 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants