Module: ShopBunny::ControllerHelpers
- Defined in:
- lib/shop_bunny/controller_helpers.rb
Overview
These methods are included in ApplicationController
Instance Method Summary collapse
- #clear_cart ⇒ Object
-
#find_cart ⇒ Object
The default behaviour is to map a Cart to a session variable ‘cart_id’.
Instance Method Details
#clear_cart ⇒ Object
22 23 24 |
# File 'lib/shop_bunny/controller_helpers.rb', line 22 def clear_cart session[:cart_id] = nil end |
#find_cart ⇒ Object
The default behaviour is to map a Cart to a session variable ‘cart_id’. You might want to overwrite this method to authorize a user. TODO This could result in a mass of empty carts. A Problem?
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shop_bunny/controller_helpers.rb', line 7 def find_cart if session[:cart_id] begin @cart = Cart.find(session[:cart_id]) rescue ActiveRecord::RecordNotFound => e @cart = Cart.create session[:cart_id] = @cart.id end else @cart = Cart.create session[:cart_id] = @cart.id end end |