Rails Project Here I Come

I’m officially ready to start my Rails Portfolio Project! Woot woot! I still don’t know what I’m going to do for it so I’m going to read the requirements tonight and brainstorm through the day tomorrow so I can start tomorrow night. I’ll also bring this up in the weekly stand up tomorrow morning and see if I can get some ideas.

I had a couple unique problems today, at least unique to me. I was working on a project all day and it’s an eCommerce store. The idea was that a User would have a Cart and you could get the cart for the User by calling current_cart. I initially created a setter and getter. However, this quickly broke down as I worked through all the tests. I was banging my head against the wall so I did some looking and ended up adding a new association to my User model.

has_one :current_cart, class_name: "Cart"

While I had implemented this before in other labs/lessons this time it clicked. The User will have one cart (makes sense) and it will be of the class Cart. So current_cart works like an alias for carts with the User model since a User has_many :carts. User.carts and User.current_cart do the same thing as far as I can tell.

Another method that hadn’t completely clicked until this project was try(). I had read the documentation on it but never implemented it. Then I hit a snag where I was raising a NoMethod error because of a nil in an if statement. I thought to myself, “This is obviously false if it’s nil.” Then the lightbulb went off. This is exactly what try() is used for. Instead of raising an error when a method is being called on nil it’ll just return nil which in turn evaluates to false. I even called it inside of an attribute which I felt accomplished by even if it’s not that big of a deal in reality.

line_item = line_items.find_by(item_id: itemid)
    if items.include?(line_item.try(:item))

I also kept up with my commit messages on this project. You can check out the finished project here. It was nice to not have to build out all the views for this. While it’s good to practice it has felt monotonous and unproductive building so many views during lessons. Especially when learning how to implement things like authentication and ending up spending more time rendering info from the DB in views than what the lesson was teaching.

I’m looking forward to hitting the ground running tomorrow night with a solid idea and getting all my migrations that I think I’ll need done as well as getting the app initialized. RubyMine has a way to start a new Rails project and I’m going to compare what that creates to what rails new project-name creates.

It’s kind of crazy to think how far I’ve come to this point. I remember when I started I would look at people’s profiles with 500+ “Number of Lessons Completed” and think about how much they must know. Or wonder how long it had taken them to get that far. Now I’m right there too.

I just realized it’s past 1am. I got sidetracked starting to think about my Rails project and if I want to implement TDD or not. It would look good but do I want to spend the time now or later? Granted, the whole idea behind TDD is writing the tests FIRST. However, even writing them after to just get the experience should be valuable too at this point in my learning.

Time spent today: 5:02
Time spent total: 296:54
Lessons completed today: 2
Lessons completed total: 518