We Recommend

The Rails Way The Rails Way
Now, for the first time, there’s a comprehensive, authoritative guide to building production-quality software with Rails. Pioneering Rails developer Obie Fernandez and a team of experts illuminate the entire Rails API, along with the Ruby idioms, design approaches, libraries, and plug-ins that make Rails so valuable.


Posted By

winson on 04/30/07


Tagged

textmate controller application cart


Versions (?)


My initialize cart


Published in: Rails 


  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 

You need to login to post a comment.