Today we were given clear instructions on how to build the order function (i.e. when a user decides to check out and make a purchase). I spent the morning finishing off the remaining 4 tasks left over from yesterday. Xdite explained that we were actually expected to finish all 6 yesterday, and that the instructions to add order function can be done separately from yesterday's tasks. But I still felt compelled to finish in the order the assignments were given.

Luckily, I figured out the 4 tasks pretty quickly (1. will not have duplicate items in cart 2. can change number of a certain item in cart 3. cannot purchase an item which has 0 quantity, 4. cannot add more quantity than what is in stock), though these functions can be improved (which I will get to when I have more time).

Then I followed the instructions closely to build out the order function, which involved creating many migrations and establishing pretty complex relationships between models.


In general I felt pretty good about myself as I completed one task after another, with occasional help from classmates to confirm if I'm on the right track (I've been going to the TA less frequently now).


Some key learning points today:

  1. "Member" vs. "Collection" - in routing, "member" sets a particular action routes for individual unit of a resource, while "collection" establishes the action for the whole resource.

  2. Redefining a variable - saying a + 1 doesn't change the value of a, but a = a + 1 does. And when a variable's value has been changed, it needs to be saved with .save method.

  3. Actions defined in the model can be called in the controller.

Worth noting a lot of these concepts were realized from talking with classmates.


One key hurdle that remains is figuring out how to call a particular method or data. For instance, what pre-defined method can be called in which of the MVC type of file? What is the difference between "CartItem", "cart_item", "cart_items", "@cart_item", and "@cart_items"? When to use "current_cart" vs. "cart" vs. "@cart"? I really hope to get a better hang of these over the course of this week.