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

Rails Projects & RubyMine

Today was long but good. I started off by hosting my first study group. Turns some people really do get some coding done on the weekends even if Slack is much quieter. We had a good talk and it was an easy way to start the day.

I got through the Pundit lab which took way longer than I thought it would but that was fine. I didn’t feel like I was beating my head against a well. Just progressing. It felt good to struggle some then overcome.

I started my first Rails Project tonight and was able to get all of the model tests passing. I’ve completely (except for this blog) switched over to RubyMine now and I’m slowing figuring out more and more about it. It’s super powerful and I see a lot of it relies on opening a project in the root folder. All of the labs for Flatiron are in a singular folder so I typically open that one folder full of folders and that throws off most of the features of RubyMine. Too many VCS repos all in one project. Tonight I got tests to run automatically upon code changes. I also realized that RubyMine could generate an image with relationships mapped for my models which is dope. In addition, I started to look at the rubocop linting and was able to remove the block from this map method and use &: instead.

# before
def total
  items.map { |item| item.price }.sum
end

# after rubocop linting
def total
  items.map(&:price).sum
end

I also decided to track my time on each project from now on. However, I completely forgot to start tracking my Rails Projects when I got to it though. Luckily Wakatime saved the day and told me how long I had been working on the project. I’m stoked that I’m on the projects even if it’s a little later in the day than I had planned on. This means I’m almost 100% going to be starting my Rails Portfolio Project tomorrow!

Time spent today: 10:26
Time spent total: 291:53
Lessons completed today: 2
Lessons completed total: 516

Useful or Not?

So last night I chose not to write a post. I attended a study group that walked through the lab I’ll be doing tomorrow on Pundit and watched a lecture. Since I didn’t do any actual writing of code I skipped the blog. However, I know how to solve the Pundit lab quickly now ;-).

I started tonight off helping out my man Mike (we did the Music Library CLI project together) set up his associations for this Sinatra portfolio project (see above). That was fun and I realized I knew how to explain to somebody else associations.

The rest of tonight was all about CanCanCan and Devise Roles. CanCanCan was a pain in the ass, to say the least. The Devise Roles labs had very little coding related to roles and the tests were more about the controllers and views. I have an intuition of sorts and know when to “phone it in” sometimes. Tonight I did that on CanCanCan. I didn’t really understand it and just kept going anyway. I chose not to dive deep into it. Later on tonight in a lecture video Avi stated that he doesn’t use CanCanCan. I guess it’s supposed to be like the SQL before Active Record. I just have a hard time wrapping my head around getting taught a gem that isn’t recommended. Either way, I’m past it now.

I’m leading my first study group in the morning. Wish me luck!

Time spent today: 4:40
Time spent total: 281:27
Lessons completed today: 5
Lessons completed total: 514

CanCanCan? I Thought It Was Can Can?

I spent a lot of time yesterday and today psyching myself out about this Devise lab. Turns out it was very straightforward. All the extra “research” I was doing was actually taking away from me getting it done. When I reset myself and approached the lab like all the others I got through it quickly.

  1. Follow ReadMe.
  2. Run tests.
  3. Look at the spec for the first test.
  4. Get the first test to pass.
  5. Repeat 2-4 until all tests pass.

That’s what I should have done from the beginning but I had the nagging little voice from my SG last week and this week that I was being hung out to learn the hard way on this one. Now, I’m working on a CanCanCan lab which doesn’t seem to be too difficult but after that is a Devise Roles lab. Maybe that’s the one everybody has been telling me about. Or maybe this stuff really does click in my head. I dunno. Either way, I’m feeling good making progress again today. I wish I hadn’t spent so much time on other stuff though because I’d probably be passed this CanCanCan lab already.

Time spent today: 1:53
Time spent total: 273:42
Lessons completed today: 2
Lessons completed total: 509

Devise Is A Beast

Today I started my Devise learning. I was feeling pretty good until I realized the teaching had stopped and I still had 10 failing tests with no way to solve them. I figured out how to pass one of the tests. I even had it passing. However, I decided to rollback my code as I had literally just been copying and pasting stuff in and I’m sure my code was all over the place. I do have two solid resources which will hopefully provide a good amount of info (outside of the Devise ReadME). The first is a Go Rails video suggested by another student and the other is a Launch School walk through that the curriculum points to. I hope between these three resources I don’t have to do too much searching to find any answers I need.

Now that I also know there are a bunch of tests I’ll work my way through the tests rather than have a bunch of random ones passing. This should help me with my workflow. I was thrown off tonight when I realized that I needed to get into learning it myself mode. I’ll be better prepared mentally tomorrow night.

Time spent today: 2:10
Time spent total: 271:49
Lessons completed today: 2
Lessons completed total: 507

OAuth Just Makes Sense, Now

I’m progressing through Rails Authentication and am happy that I completed the Omniauth section today. It was my goal and I hit it. Tomorrow I start tackling Devise. Something about OAuth that makes a lot more sense to me now is letting someone else worry about the user and their data (to an extent). I can locally store a password or I can let someone else worry about the security and I can just use that third party to verify a person is who they say they are. It would be cost prohibitive for a small app to create all the security features someone like Google or Facebook has now implemented. I mean, Google with throw Captchas at me if I log in from a different browser or even log me out if I log in from a new device in a different geographic area (I’ve done it). Also, the 2-factor authentication that many people now use. So I just send a person to one of these services and have them confirm their info for me.

Now I’m only at the start of this rabbit hole but this makes sense. How to properly implement this with multiple OAuth providers will be fun to learn about. I’m sure someone smarter than me has already solved this problem though.

I was able to participate in another Stand Up this morning and stated that I felt like I could be working on my Rails projects by this weekend and have my Rails Portfolio Project submitted by the 21st. I was told that sounded like a doable timeline so that made me very happy. I can hopefully have that assessment done before the end of the month and be into JS going into June.

Time spent today: 2:33
Time spent total: 269:39
Lessons completed today: 3
Lessons completed total: 505

Let’s Keep It Safe With Authentication

It was a strong day and I moved into Authentication. Authentication is going to be a beast I can tell. However, it looks like because it’s such an important topic there are a lot of best practices and good documentation out there. I still haven’t wrapped my head around the Sessions Controller 100% but knowing that it was almost identical in 3 separate labs tells me it’s a relatively static and consistent concept for what I’ll be doing.

Sundays seem to be quiet across there were probably <10 messages across all the channels I’m a part of on the NashDev Slack and only a few people chatting in the Learn (I use Learn and Flatiron interchangeably) Slack. I wrote my code for most of the day using RubyMine. It feels slow compared to Atom but I know that’s because it’s ridiculously powerful. It’s like using Notepad versus Word. I think I’ll be able to appreciate it more when I build out my Rails projects. Things, where there are more freedom and chance to mess up, might show off the power of the IDE better. When I’m literally inside a test suite box the IDE doesn’t have much to offer that text editors don’t have. Please correct me if I’m wrong.

I’m searching for things to write about sometimes (it seems obvious to me), however, I’m not going to stop writing.

I’m ready to start tackling the first Rails project. I’ve seen a few people looking to pair and the instructor stating that people who were well into Authentication could jump in on the first project. I’ll be looking for someone to take on that task with and hopefully be on my Rails portfolio project before next weekend. If I can start it before Saturday I think there’s a strong probability it’ll be done before the 22nd as that’ll give me 2 weekends of full days bookending a week of shorter days.

I’m working on some other projects now outside of Flatiron. Trying to get the bones around a continuous group project that we can work on for freeCodeCamp Nashville. I think it’ll be good. Trying not to get too distracted but it’s a nice thing to mix in. Example, learning how to deploy Ghost to a DigitalOcean droplet, which actually wasn’t hard. Even better, upgrading that install via command line. I really want to deploy Discourse but I can’t think of anything I’m involved with that it would be useful for right now. O well, in time.

Time spent today: 7:55
Time spent total: 267:06
Lessons completed today: 13
Lessons completed total: 502