Over the weekend I spent some time improving the visuals of the site. I came across a template for men's fashion and decided to create a men's fashion site as I had been shopping for a tuxedo prior to the program.
Today we began Phase 2 of the e-commerce project. This phase involves creating a shopping cart and building all of the necessary functionalities around it. We were given hints on how to add a shopping cart upfront, but had to figure out on our own how to increase the shopping cart's functionalities.
I managed to complete Step 1: adding in the shopping cart, creating an index page of cart items, and has a total sum of all the cart items' price. For the remaining 6 tasks, I only managed to complete 2 of them today: clearing shopping cart, and removing an individual item from shopping cart.
During today's assignment I had to do a lot more thinking rather than simply copy/pasting codes I had written for previous projects. I was stuck trying to create a remove_item_from_cart action by reverse-engineering the commands used to add_item_to_cart. After getting stuck on this for an hour or so, I decided to go ahead and create a controller for cart_items and used the destroy method to remove the cart item instead.
In addition, when I added the shopping cart function, I encountered the database issue once again, with reported error:
After trying the
rake db:migrate command multiple times to no avail, I followed the database migration fix that I had written about earlier and resolved the issue.
Adding the shopping cart was the firt time that we are departing from the plain CRUD methods when creating a model. In building the clear_cart method, we did not use the destroy method, but rather a post action created in the model, by doing the following:
Define in controller
(Careful not to place this under the "private" section otherwise it won't be callable globally)
Adding button in view
The specific route for the already defined clear_cart action can be found using
rake routes command:
I realize now that there are actions beyond CRUD methods that we can define on our own as long as we get the logic right.
In conversing with others in the class, I realize that though I can build certain functions by Googling and referencing prior projects, there were a lot of basic Ruby terminologies and logic that I am still unfamiliar with, which hinders my ability to discuss with classmates on coming up with solutions. I will need to spend more time on Ruby basics.