Happy Easter

I decided to take the weekend off and enjoy the Easter holiday with the family. I had been going hard for almost 7 straight weeks. Back at it tomorrow. I also ordered my Code & Quill Origin this weekend. Looking forward to getting my notebooks just in time to take notes on Rails.

Time spent today: 0:00
Time spent total: 188:40
Lessons completed today: 0
Lessons completed total: 405

Make It Look Nice

So about that not being fancy that I talked about last night. I took a good chunk of time today and figured out how to implement Bootstrap in my portfolio project. I figured this was my first web app and should probably look somewhat nice. I have a navbar that changes if you’re logged in or not and then I’m using the form and typography stylings. It’s definitely taking me longer to write my forms out and I’m making sure my app actually will look good so that is taking more time as well. However, I think I’m going to be more proud of this when I’m done. You can follow my progress on my project here. Although, that link might break in the future as I’ll probably rename my repo to something less stalkerish lol.

It took me a long time to get my naming correct for my has_many to has_many relationship. Between the models and the DB it was a mistake in what needed to be plural that ultimately took some time to figure out. I’m happy that I don’t have to keep up with these associations in any complex manner. I don’t know why but I’m exhausted right now. I’m usually still humming along at 11:15pm but not tonight. I’m fighting to stay awake. I made some great progress today on my Sinatra project and I’m happy with where I’m at. I could’ve been closer to being done but I know that I’ll be more proud to show off my project because of how it looks.

Time spent today: 6:20
Time spent total: 188:40
Lessons completed today: 0
Lessons completed total: 405

Crushing Fwitter Tonight was Sweet

It’s late so I’ll be brief. I crushed my project tonight and I’m ready to start my Sinatra portfolio project tomorrow. I think I can have an ugly version (desktop down design, raw forms, no nav bar or footer) done tomorrow at some point and then leave it alone until after my project review with an instructor. We’ll see how that goes. The requirements are:

  1. Build an MVC Sinatra Application.
  2. Use ActiveRecord with Sinatra.
  3. Use Multiple Models.
  4. Use at least one has_many relationship
  5. Must have user accounts. The user that created a given piece of content should be the only person who can modify that content
  6. You should validate user input to ensure that bad data isn’t created

So it might be ambitious to think I can finish that in a day or two but I’m confident I can with what I have planned.

I was able to utilize Active Record Validations tonight. I also included HTML5 required tags in my forms. However, the tests were sending raw params data to the post route so it was bypassing utilizing my forms to test. I guess this is good though because it creates a situation where if someone sends bad data to the server through a method other than the server it’ll reject it. However, I wouldn’t want the server hit every time a bad form is input. Maybe a combo of the two makes sense? That way data is validated in the browser and when being saved to the server. Here’s what an Active Record Validation looks like from Rails Guides:

class Person < ApplicationRecord
  validates :name, presence: true
end

Person.create(name: "John Doe").valid? # => true
Person.create(name: nil).valid? # => false

I also decided to buy the Cast Iron Design Eco Pocket-Sized Notebook pack of 3 to start. I realized that AMEX is offering a bonus if you redeem points towards purchases until the end of the month. While redemption values are almost always lowest when using AMEX points for bill credits with the 20% bump it’s worth using for a few small things. Considering we have 70k of them $12 won’t make a dent in that. I still plan to get a Code & Quill Origin when they’re not sold out anymore. The fact that there are spacing markers that will make written code look good is sweet (not like you can’t do that on graph paper but still).

I think one of the biggest things I’ve been doing that has helped me not get bogged down as I’m moving through the curriculum and projects is to not get too fancy. I’m also not overthinking it. I’m being very straightforward in what I’m putting together and making things that work. Could pretty much everything be better? Yes. However, I’m looking to have a body of work to present. I honestly feel that when it comes job hiring time the strength of the code will outweigh the shiny UI’s. I still plan on going back and polishing everything up and making it look nice (or at least nicer) than the project requirements require.

Time spent today: 3:13
Time spent total: 182:20
Lessons completed today: 1
Lessons completed total: 405

Writing it Down Always Helps

Taking it easy tonight. I have to get some work done for Gift of Adoption Fund, the non-profit I volunteer on the board for here in TN. Shameless plug, Like our Facebook Page please. I finished up the NYC lab in <30 minutes. The second controller and views were much more simple. I didn’t get a chance to refactor my code yet. However, I don’t think helper methods are needed as I didn’t use that code anywhere in my other controller. Maybe though, maybe. I watched the two lecture videos and finished my DB migrations and building out the models on my first Sinatra project as well tonight. I still go back and forth with feeling like I’m getting enough accomplished each day but hitting milestones and goals (even if 3 days late) feels good. My wife is off Friday so hopefully, that’ll allow me some good time to get work done since we have a birthday party Saturday and it’s Easter on Sunday.

On another note, I’m trying to figure out a notebook to buy. I’ve used Moleskine’s in the past. Nothing against them but not what I’m looking for right now. Field Notes seem expensive for what they are and you’re paying for the cool factor more than the notebook. So, I did some research. Deciding between the Cast Iron Design Eco Pocket-Sized Notebook, any of the Code & Quill books although at this price I’d go hardcover, Word. Dot Grid because it’s Field Notes but not, or MUJI Recycled Paper Bing Notebook A5 because they’re dirt cheap. Let me know what you think. I’m leaning towards Code & Quill most likely. I think the larger hardcover books will be beneficial to have segmented by language and framework. I can create personal reference libraries in them and add as time goes on. I can have a master Ruby book, a JS book, a Rails book, is the thought at least. Or maybe I start with smaller books and if a top turns in to two books it gets a C&Q book and I transcribe over what I already have which wouldn’t be much at that point.

Time spent today: 1:50
Time spent total: 179:08
Lessons completed today: 3
Lessons completed total: 404

Helper Methods Tested, How to Not Repeat Yourself

I’m on a killer roll right now blowing through this NYC lab. Built my 3 tables and 1 JOIN table migrations. Built out the associated models. Built out all the views and one controller. Have one controller and its views left now. If I didn’t have kids that were going to wake me up between 6:30am and 8:00am I’d finish it up. I think it’ll take me maybe 30 more mins (mostly because A LOT of it is going to be similar to the controller & views I just built) but sleep is needed. I also need to finish doing my part of the household chores (dishes tonight) before bed so in the interest of rest I’ve stopped.

However, I’m pretty hype and think I’ll still be on schedule to finish the review videos tomorrow night. I also feel more confident about attacking the portfolio project. The only part I haven’t really dug into is the UI. I figure a basic bootstrap will do. Utilize the layout.erb to have a consistent header and footer and I’ll be happy at this point in time (when that time comes).

I’m contemplating creating helper methods for my controllers. Currently, the one controller I finished tonight (I’ll do the other and all its views tomorrow) is:

class FiguresController < ApplicationController

  get '/figures' do
    @figures = Figure.all
    erb :'figures/index'
  end

  get '/figures/new' do
    @figures = Figure.all
    @landmarks = Landmark.all
    @titles = Title.all
    erb :'figures/new'
  end

  get '/figures/:id' do
    @figure = Figure.find(params[:id])
    erb :'figures/show'
  end

  post '/figures/:id' do
    @figure = Figure.find(params[:id])
    @figure.update(params[:figure])

    if !params[:title][:name].empty?
      if !!params[:figure][:title_ids]
        params[:figure][:title_ids] << Title.create(params[:title]).id
      else
        params[:figure][:title_ids] = []
        params[:figure][:title_ids] << Title.create(params[:title]).id
      end
    end
    @figure.title_ids = params[:figure][:title_ids]

    if !params[:landmark][:name].empty?
      if !!params[:figure][:landmark_ids]
        params[:figure][:landmark_ids] << Landmark.create(params[:landmark]).id
      else
        params[:figure][:landmark_ids] = []
        params[:figure][:landmark_ids] << Landmark.create(params[:landmark]).id
      end
    end
    @figure.landmark_ids = params[:figure][:landmark_ids]

    @figure.save

    redirect to "/figures/#{@figure.id}"
  end

  get '/figures/:id/edit' do
    @figure = Figure.find(params[:id])
    @landmarks = Landmark.all
    @titles = Title.all
    erb :'figures/edit'
  end

  post '/figures' do
    @figure = Figure.create(params[:figure])

    if !params[:title][:name].empty?
      if !!params[:figure][:title_ids]
        params[:figure][:title_ids] << Title.create(params[:title]).id
      else
        params[:figure][:title_ids] = []
        params[:figure][:title_ids] << Title.create(params[:title]).id
      end
    end
    @figure.title_ids = params[:figure][:title_ids]

    if !params[:landmark][:name].empty?
      if !!params[:figure][:landmark_ids]
        params[:figure][:landmark_ids] << Landmark.create(params[:landmark]).id
      else
        params[:figure][:landmark_ids] = []
        params[:figure][:landmark_ids] << Landmark.create(params[:landmark]).id
      end
    end
    @figure.landmark_ids = params[:figure][:landmark_ids]

    @figure.save

    redirect to "/figures/#{@figure.id}"
  end
end

The main parts that violate DRY (don’t repeat yourself) should be readily evident in:

if !params[:title][:name].empty?
  if !!params[:figure][:title_ids]
    params[:figure][:title_ids] << Title.create(params[:title]).id
  else
    params[:figure][:title_ids] = []
    params[:figure][:title_ids] << Title.create(params[:title]).id
  end
end
@figure.title_ids = params[:figure][:title_ids]

if !params[:landmark][:name].empty?
  if !!params[:figure][:landmark_ids]
    params[:figure][:landmark_ids] << Landmark.create(params[:landmark]).id
  else
    params[:figure][:landmark_ids] = []
    params[:figure][:landmark_ids] << Landmark.create(params[:landmark]).id
  end
end
@figure.landmark_ids = params[:figure][:landmark_ids]

Not only are these lines with a nested if statement not elegant but they are carbon copies of each other. In addition, I foresee using almost the same exact methods in my other controller. I’ll probably have one of these if blocks utilizing figure_ids but other than that it’ll be pretty close. We’ll see and if that’s true I’ll definitely create 3 helper methods and just use those if I can. It’ll be good practice in building helper methods for the controller because I haven’t done that before. I’ve built a module for the models in my last lab.

A note I took that didn’t make sense at the time was:

Define helper methods in the Application Controller

After tonight I see exactly why. This is because the individual controllers (at least in my case) are inheriting from the app controller. I was thinking initially I would have to create a Helper class of some sort and then utilize them that way but I have this basically empty file that the controllers are already using so it makes sense to put helper methods right in there.

Time spent today: 2:09
Time spent total: 177:17
Lessons completed today: 0
Lessons completed total: 401

Improved Playlister with Quick Superior Code

Got a large lab done tonight. Right on schedule. I was done 2 minutes after 11pm. I basically took the Music Library CLI app that I made earlier in the curriculum and turned it into a much more user-friendly Sinatra MVC web app. The final code can be found here. The biggest challenge I had was setting up my databases and models. Actually, just with the JOIN table. However, I know the more I do this the easier it will get. It’s still very new and a complex thing to grasp.

I also attended a study group this afternoon and saw another student’s Sinatra portfolio project he was working on. After quickly glancing at the project info, this line gave me an idea for my project:

The app should be a custom app that is created to track something important to you.

Since my family just moved into a new neighborhood in January I’ve been keeping track of who our neighbors are in an EverNote Doc. Pretty much, address, the matriarch, patriarch and kids with ages. I figured I could have 3 tables in this app. One for the House with an address. Then the House has_many Parents and has_many Kids through Parents. Parents with Name and Phone Number values. Parents will belongs_to a House and has_many Kids. Kids will have a name, age, and sex fields (for those unisex names). Kids will has_many Parents and belongs_to a House through Parents. I told my instructor this briefly during the study group and he said that was more than enough to fulfill the requirements of the project. All the project requires is a single has_many relationship in terms of the database aspect.

I also asked about if there was a preference between Active Record Validations or HTML5 Form Validations. He said HTML5 form validations were further in the curriculum so most would not be using them at this point in time. However, it’s just use case choice. Of course, HTML5 form validations won’t hit the DB so there’s that as well he said. I didn’t realize how complex HTML5 form validation was until I looked it up (see the link at the beginning of this paragraph) and now I realize why it isn’t taught until later. I was thinking of simple input constraints like those found here. Now there are some things that must hit the server to validate. For example, if you wanted to ensure an email address hadn’t been registered already there is only one way to check that. This is where something like Active Record’s uniqueness helper comes into play. I’m not sure how far down this rabbit hole I’ll go building out my project. Maybe just a simple <type="tel"> in what I was thinking of above. Although, since this is a portfolio project I’ll make sure to keep a set of features I want to implement to improve the app. I’ll make sure to work on getting these things done when the job hunt starts. Currently, the goal is to get to that point as quickly as possible so I’m completing projects with close to the bare minimum requirements.

Time spent today: 3:16
Time spent total: 175:09
Lessons completed today: 1
Lessons completed total: 401

Launching Through Roadblocks Quickly is Monumental

Today was the day of roadblocks. I spent probably 3 hours working with Learn Experts on problems. For the most part, these were dev environment issues or weird test issues and not working through my code and learning new things. I did learn some things about debugging though. I learned to check my Gemfile because if a gem is missing weird things happen. I’m not sure how I was able to run shotgun without having the gem in the Gemfile but it worked and then I got odd errors in my browser. Easy fix once it was figured out but that took an hour. I also learned that when doing TDD work on each test as you go rather than the entire thing. I had two forms that were very similar so I copied and pasted the first into the code for the second. I made all the edits I thought I needed to and then ran the tests. I kept getting an odd error saying an element wasn’t there but I knew it was. Turns out code further down in my form was breaking my entire view and thus Capybara was unable to read the entire page. If it can’t read the page at all, of course, the element will be missing. So I commented out the rest of the code and worked test by test after that and had much more success. However, figuring this out took another hour tonight.

All this time having others review my code let me beat my brother in a game of chess :-). If you want to play me you can find me on Chess.com at my profile here.

I also learned more about databases and how I’ll utilize them with ActiveRecord in my Sinatra apps. Specifically, I know that the JOIN table will come up again in the future. As this is one of the more confusing topics I made sure to save this overview:

A join table is a table that only has two columns. To keep up with the online store example, this table would contain a user_id and item_id. Each row in this table would contain a user’s ID and an item’s ID. We call this join table user_items. The has_many :through is always singular and in the first part of the join table name, and the belongs_to portion of the relationship is pluralized in the second part of the table name.

I’m 2 labs and 2 lectures behind my goal :-(. The new goal is to be done with these 4 things by Wednesday night. I think I can finish each lab in a 3-hour sitting so that’s Monday and Tuesday night then watch the lectures on Wednesday. I looked and I’m about 10 hours behind the amount of time I wanted to code this week and that’s basically what I missed it by. I need to re-up on my strict adherence to my schedule. While I’m moving along I could be further along than I am and closer to being employed at this point in time. I’m dreading the feeling I’ll have if I make that one extra tuition payment when I know it could’ve been avoided.

Time spent today: 6:47
Time spent total: 171:53
Lessons completed today: 8
Lessons completed total: 400