/ Published in: Rails
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Initialize shopping cart. def initialize_cart # #1 # -- # if session[:cart_id] # @cart = Cart.find(session[:cart_id]) # else # @cart = Cart.create # session[:cart_id] = @cart.id # end # #2 # -- # if session[:cart] # @cart = session[:cart] # else # @cart = Cart.create # session[:cart] = @cart # end # #3 @cart = session[:cart] ||= Cart.create end