Skip to content

Instantly share code, notes, and snippets.

@rocodev-tech
Created June 12, 2014 22:04
Show Gist options
  • Save rocodev-tech/13dd9d8f91c731e5c1b5 to your computer and use it in GitHub Desktop.
Save rocodev-tech/13dd9d8f91c731e5c1b5 to your computer and use it in GitHub Desktop.
app/controllers/application_controller.rb
helper_method :current_cart
def current_cart
@current_cart ||= find_cart
end
def find_cart
cart = Cart.find_by(id: session[:cart_id])
unless cart.present?
cart = Cart.create
end
session[:cart_id] = cart.id
cart
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment