Module: CartHelper
- Defined in:
- lib/generators/templates/cart_helper.rb
Instance Method Summary collapse
-
#cart ⇒ Object
Returns the cart.
-
#empty_cart ⇒ Object
Cleans up the cart.
-
#find_cart ⇒ Object
Find the cart.
-
#link_to_add_to_cart(product) ⇒ Object
Link to add to cart.
-
#link_to_empty_cart ⇒ Object
Link to empty the cart.
-
#link_to_remove_from_cart(product) ⇒ Object
Link to remove from cart.
Instance Method Details
#cart ⇒ Object
Returns the cart
31 32 33 |
# File 'lib/generators/templates/cart_helper.rb', line 31 def cart find_cart end |
#empty_cart ⇒ Object
Cleans up the cart
9 10 11 12 13 |
# File 'lib/generators/templates/cart_helper.rb', line 9 def empty_cart session[:cart] = nil flash[:notice] = "Your cart is empty" redirect_to :back end |
#find_cart ⇒ Object
Find the cart
4 5 6 |
# File 'lib/generators/templates/cart_helper.rb', line 4 def find_cart session[:cart] ||= Cart.new end |
#link_to_add_to_cart(product) ⇒ Object
Link to add to cart
21 22 23 |
# File 'lib/generators/templates/cart_helper.rb', line 21 def link_to_add_to_cart(product) link_to "Add to cart", add_to_cart_path(product.id) end |
#link_to_empty_cart ⇒ Object
Link to empty the cart
16 17 18 |
# File 'lib/generators/templates/cart_helper.rb', line 16 def link_to_empty_cart link_to "Empty the car", empty_cart_path end |
#link_to_remove_from_cart(product) ⇒ Object
Link to remove from cart
26 27 28 |
# File 'lib/generators/templates/cart_helper.rb', line 26 def link_to_remove_from_cart(product) link_to "Remove from cart", remove_from_cart_path(product.id) if find_cart.find_item(product) end |