SlideShare uma empresa Scribd logo
1 de 20
Creating a Smarter Cart Jason Noble http://jasonnoble.org
Adding a count to our cart rails generate migration add_quantity_to_line_itemquantity:integer Rails recognizes add_XXX_to_TABLE Rails recognizes remove_XXX_to_TABLE Modify the migration to specify a default value add_column :line_items, :quantity, :integer, :default => 1
Add Product Method app/models/cart.rb
Update Line Items Controller Change create method
Modify Cart Show View Add the quantity to the cart view app/views/carts/show.html.erb
Still have duplicates
Write a migration to fix existing carts  rails generate migration combine_items_in_cart
Add an undo option Modify the migration self.down method rake db:rollback
Handling Errors
Sending messages to the user Rails has a structure called flash flash is a Hash that you can you can store stuff in as you process a request Contents of the flash are available to the next request and then automatically deleted Store error and debug messages in the flash to help users understand what’s happening flash is stored in the user’s session to make it available between requests
Add a message to the flash app/controllers/carts_controller.rb
Verify it works http://localhost:3000/carts/wibble
Emptying your cart app/views/carts/show.html.erb
Emptying your cart (cont.) app/controllers/carts_controller.rb
Run your tests often rake test test/functional/carts_controller_test.rb
Better Cart View app/views/carts/show.html.erb
Add total_price methods app/models/line_item.rb app/models/cart.rb
Make it prettier public/stylesheets/depot.css
What we covered Adding/Removing a column to an existing table with a default value Migrating existing table data into new format Providing flash notices to customer Using the logger to log events Deleted a record Adjusted the way the cart is viewed, using CSS
Homework Create a migration that stores the product price in the line item table.  Modify add_product method to capture the price. Add unit tests which add unique products and duplicate products. Use the flash functionality to show helpful messages Add the ability to delete individual line items from the cart.  Bonus points to decrease quantity by 1.

Mais conteúdo relacionado

Semelhante a Smarter cart

Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01Jason Noble
 
Foundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxFoundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxhanneloremccaffery
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendalltutorialsruby
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendalltutorialsruby
 
Dynamic Web Pages Ch 3 V1.0
Dynamic Web Pages Ch 3 V1.0Dynamic Web Pages Ch 3 V1.0
Dynamic Web Pages Ch 3 V1.0Cathie101
 
Online shopping prasentation
Online shopping prasentationOnline shopping prasentation
Online shopping prasentationAtul Kumar
 
Cakephp's Cache
Cakephp's CacheCakephp's Cache
Cakephp's Cachevl
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04Vivek chan
 
DDD-rail Your Monorail
DDD-rail Your MonorailDDD-rail Your Monorail
DDD-rail Your MonorailAndrew Hao
 
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017 So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017 Evan Mullins
 
Add new object in a dms object link sap q&a
Add new object in a dms object link   sap q&aAdd new object in a dms object link   sap q&a
Add new object in a dms object link sap q&aJalendhar Merugu
 
The Chaos Tools Suite
The Chaos Tools SuiteThe Chaos Tools Suite
The Chaos Tools Suitemerlinofchaos
 
dairy farm mgmt.pptx
dairy farm mgmt.pptxdairy farm mgmt.pptx
dairy farm mgmt.pptxMusabInamdar2
 
The 'Client' Template - Illustrated!
The 'Client' Template - Illustrated!The 'Client' Template - Illustrated!
The 'Client' Template - Illustrated!Randy Carey
 
Ruby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsRuby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsEmad Elsaid
 

Semelhante a Smarter cart (20)

Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01Cart creation-101217222728-phpapp01
Cart creation-101217222728-phpapp01
 
E-Bazaar
E-BazaarE-Bazaar
E-Bazaar
 
Foundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxFoundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docx
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
 
Dynamic Web Pages Ch 3 V1.0
Dynamic Web Pages Ch 3 V1.0Dynamic Web Pages Ch 3 V1.0
Dynamic Web Pages Ch 3 V1.0
 
Online shopping prasentation
Online shopping prasentationOnline shopping prasentation
Online shopping prasentation
 
Rails notification
Rails notificationRails notification
Rails notification
 
Offline Storage
Offline StorageOffline Storage
Offline Storage
 
Cakephp's Cache
Cakephp's CacheCakephp's Cache
Cakephp's Cache
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
Shopify Partner Social
Shopify Partner SocialShopify Partner Social
Shopify Partner Social
 
DDD-rail Your Monorail
DDD-rail Your MonorailDDD-rail Your Monorail
DDD-rail Your Monorail
 
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017 So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
 
Add new object in a dms object link sap q&a
Add new object in a dms object link   sap q&aAdd new object in a dms object link   sap q&a
Add new object in a dms object link sap q&a
 
The Chaos Tools Suite
The Chaos Tools SuiteThe Chaos Tools Suite
The Chaos Tools Suite
 
dairy farm mgmt.pptx
dairy farm mgmt.pptxdairy farm mgmt.pptx
dairy farm mgmt.pptx
 
The 'Client' Template - Illustrated!
The 'Client' Template - Illustrated!The 'Client' Template - Illustrated!
The 'Client' Template - Illustrated!
 
Ruby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsRuby on rails3 - introduction to rails
Ruby on rails3 - introduction to rails
 
Rest in Rails
Rest in RailsRest in Rails
Rest in Rails
 

Mais de Jason Noble

Mais de Jason Noble (12)

Intro to TDD and BDD
Intro to TDD and BDDIntro to TDD and BDD
Intro to TDD and BDD
 
Davinci git brown_bag
Davinci git brown_bagDavinci git brown_bag
Davinci git brown_bag
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp Atlanta
 
Validation unit testing
Validation unit testingValidation unit testing
Validation unit testing
 
Creating the application
Creating the applicationCreating the application
Creating the application
 
Capistrano
CapistranoCapistrano
Capistrano
 
Atlanta Pm Git 101
Atlanta Pm Git 101Atlanta Pm Git 101
Atlanta Pm Git 101
 
Regex Intro
Regex IntroRegex Intro
Regex Intro
 
Git101
Git101Git101
Git101
 
Git Atlrug
Git AtlrugGit Atlrug
Git Atlrug
 
Git102
Git102Git102
Git102
 

Smarter cart

  • 1. Creating a Smarter Cart Jason Noble http://jasonnoble.org
  • 2. Adding a count to our cart rails generate migration add_quantity_to_line_itemquantity:integer Rails recognizes add_XXX_to_TABLE Rails recognizes remove_XXX_to_TABLE Modify the migration to specify a default value add_column :line_items, :quantity, :integer, :default => 1
  • 3. Add Product Method app/models/cart.rb
  • 4. Update Line Items Controller Change create method
  • 5. Modify Cart Show View Add the quantity to the cart view app/views/carts/show.html.erb
  • 7. Write a migration to fix existing carts rails generate migration combine_items_in_cart
  • 8. Add an undo option Modify the migration self.down method rake db:rollback
  • 10. Sending messages to the user Rails has a structure called flash flash is a Hash that you can you can store stuff in as you process a request Contents of the flash are available to the next request and then automatically deleted Store error and debug messages in the flash to help users understand what’s happening flash is stored in the user’s session to make it available between requests
  • 11. Add a message to the flash app/controllers/carts_controller.rb
  • 12. Verify it works http://localhost:3000/carts/wibble
  • 13. Emptying your cart app/views/carts/show.html.erb
  • 14. Emptying your cart (cont.) app/controllers/carts_controller.rb
  • 15. Run your tests often rake test test/functional/carts_controller_test.rb
  • 16. Better Cart View app/views/carts/show.html.erb
  • 17. Add total_price methods app/models/line_item.rb app/models/cart.rb
  • 18. Make it prettier public/stylesheets/depot.css
  • 19. What we covered Adding/Removing a column to an existing table with a default value Migrating existing table data into new format Providing flash notices to customer Using the logger to log events Deleted a record Adjusted the way the cart is viewed, using CSS
  • 20. Homework Create a migration that stores the product price in the line item table. Modify add_product method to capture the price. Add unit tests which add unique products and duplicate products. Use the flash functionality to show helpful messages Add the ability to delete individual line items from the cart. Bonus points to decrease quantity by 1.