EndPointCorp / end-point-blog

End Point Dev blog
https://www.endpointdev.com/blog/
17 stars 65 forks source link

Comments for Ecommerce on Sinatra: A Shopping Cart Story #423

Open phinjensen opened 6 years ago

phinjensen commented 6 years ago

Comments for https://www.endpointdev.com/blog/2011/03/ecommerce-sinatra-shopping-cart/ By Steph Skardal

To enter a comment:

  1. Log in to GitHub
  2. Leave a comment on this issue.
phinjensen commented 6 years ago
original author: Clint Pachl
date: 2011-03-04T23:16:48-05:00

Because Sinatra's beautiful DSL makes REST so easy, you could update your routes:

app.post '/cart/add' app.post '/cart/update' app.get '/cart/remove/:product_id'

to a more RESTful version:

app.post '/cart' app.put '/cart/:product_id' app.delete '/cart/:product_id'

Then enable the Sinatra :method_override option to automatically detect the HTTP verb sent in forms (e.g. _method="put"). Then remember to include _method as a hidden variable in PUT and DELETE forms.

Here's a RESTful resource table: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

Great article; very professionally done.

phinjensen commented 6 years ago
original author: Steph Skardal
date: 2011-03-07T09:50:11-05:00

Thanks for the comments - I'll look into cleaning up these RESTful routes.

phinjensen commented 6 years ago
original author: joselo
date: 2011-06-29T01:09:18-04:00

talking about shopping carts, I wondering if should I duplicate or save the product in other table just for the reason that the user can have an inventary of their orders and if I modify the product that the client bought it will be an inconsistence. Because the cliente will see a differente product, do you know what I mean :), wich could be a good solution without make an asociation directly with the product model. I'm not sure but a duplicate table.. that sucks :-(

Any ideas, thanks!

phinjensen commented 6 years ago
original author: Ronny Ager-Wick
date: 2011-10-18T12:14:56-04:00

joselo, if you don't want to store a duplicate of your product model on the order lines, you can: