Skip to content

Instantly share code, notes, and snippets.

@berellevy
Created August 19, 2020 12:50
Show Gist options
  • Save berellevy/2379d3be0072726cc470bd8c87c1b13e to your computer and use it in GitHub Desktop.
Save berellevy/2379d3be0072726cc470bd8c87c1b13e to your computer and use it in GitHub Desktop.
class Cart < ApplicationMethod
...
def make_purchase
if cart_items.length > 0
p = Purchase.create(user: self.user)
p.cart_items = self.cart_items
p.save
return p.display_purchase
else
return {error: "No items to purchase"}
end
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment