Skip to content

Instantly share code, notes, and snippets.

@bensie
Created February 9, 2009 23:19
Show Gist options
  • Save bensie/61089 to your computer and use it in GitHub Desktop.
Save bensie/61089 to your computer and use it in GitHub Desktop.
# controllers/application.rb
def current_cart
if session[:cart_id]
@current_cart ||= Cart.find(session[:cart_id])
session[:cart_id] = nil if @current_cart.purchased_at
end
if session[:cart_id].nil?
@current_cart = Cart.create!
session[:cart_id] = @current_cart.id
end
@current_cart
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment