My initialize cart


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # Initialize shopping cart.
  2. def initialize_cart
  3. # #1
  4. # --
  5. # if session[:cart_id]
  6. # @cart = Cart.find(session[:cart_id])
  7. # else
  8. # @cart = Cart.create
  9. # session[:cart_id] = @cart.id
  10. # end
  11.  
  12. # #2
  13. # --
  14. # if session[:cart]
  15. # @cart = session[:cart]
  16. # else
  17. # @cart = Cart.create
  18. # session[:cart] = @cart
  19. # end
  20.  
  21. # #3
  22. @cart = session[:cart] ||= Cart.create
  23. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.