Module: ShopBunny::ControllerHelpers

Defined in:
lib/shop_bunny/controller_helpers.rb

Overview

These methods are included in ApplicationController

Instance Method Summary collapse

Instance Method Details

#clear_cartObject



22
23
24
# File 'lib/shop_bunny/controller_helpers.rb', line 22

def clear_cart
  session[:cart_id] = nil
end

#find_cartObject

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