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

I Suddenly Know How It All Fits Together Better

lego stormrooper on a skateboard

I moved through a lot of curriculum today. However, I really want to hit the goal I set two weeks ago and I’m on the cusp of it! I had 21 lessons/labs to go for my goal when I checked early in the day. So I set a goal of 11 more today (I had already finished 2) and finish tomorrow. I missed it by one only because it’s late and I hit an hour and a half review lecture. Since I’m working on ActiveRecord sessions and authentication I want to pay better attention to this lecture than I usually do. Maybe even take a note or two :-).

Ealy in the day I got stuck on a nested forms lab. I was getting an error:

Failures:
  1) App POST /teams submits the form
     Failure/Error: click_button 'submit'
     TypeError:
       expected Hash (got String) for param `name'

but I couldn’t figure out why. My code was:

<h1>Create a Team and Heroes!</h1>
<form action="/teams" method="POST">
  <p>Team Name: <input type="text" name="team[name]"></p>
  <p>Team Motto: <input type="text" name="team[motto]"></p>
  <h2>Hero 1</h2>
  <p>Hero's Name: <input id="member1_name" type="text" name="team[name][hero][][name]"></p>
  <p>Hero's Power: <input id="member1_power" type="text" name="team[name][hero][][power]"></p>
  <p>Hero's Biography: <input id="member1_bio" type="text" name="team[name][hero][][bio]"></p>
  <h2>Hero 2</h2>
  <p>Hero's Name: <input id="member2_name" type="text" name="team[name][hero][][name]"></p>
  <p>Hero's Power: <input id="member2_power" type="text" name="team[name][hero][][power]"></p>
  <p>Hero's Biography: <input id="member2_bio" type="text" name="team[name][hero][][bio]"></p>
  <h2>Hero 3</h2>
  <p>Hero's Name: <input id="member3_name" type="text" name="team[name][hero][][name]"></p>
  <p>Hero's Power: <input id="member3_power" type="text" name="team[name][hero][][power]"></p>
  <p>Hero's Biography: <input id="member3_bio" type="text" name="team[name][hero][][bio]"></p>
  <button type="submit" value="submit">Submit</button>
</form>

I kept thinking, “How can form input be anything other than a String? Why is it expecting a hash?” I reached out to a Learn Expert (they’re like Teaching Assistants who are available almost 24/7 to help) and it took almost an hour to resolve it. However, figured out that because my third line had name="team[name] whenever I called a nested hash that contained team[name] it was returning the string I input instead of setting the params nested hash array to the proper thing. A quick change of my code to:

<h1>Create a Team and Heroes!</h1>
<form action="/teams" method="POST">
  <p>Team Name: <input type="text" name="team[name]"></p>
  <p>Team Motto: <input type="text" name="team[motto]"></p>
  <h2>Hero 1</h2>
  <p>Hero's Name: <input id="member1_name" type="text" name="team[hero][][name]"></p>
  <p>Hero's Power: <input id="member1_power" type="text" name="team[hero][][power]"></p>
  <p>Hero's Biography: <input id="member1_bio" type="text" name="team[hero][][bio]"></p>
  <h2>Hero 2</h2>
  <p>Hero's Name: <input id="member2_name" type="text" name="team[hero][][name]"></p>
  <p>Hero's Power: <input id="member2_power" type="text" name="team[hero][][power]"></p>
  <p>Hero's Biography: <input id="member2_bio" type="text" name="team[hero][][bio]"></p>
  <h2>Hero 3</h2>
  <p>Hero's Name: <input id="member3_name" type="text" name="team[hero][][name]"></p>
  <p>Hero's Power: <input id="member3_power" type="text" name="team[hero][][power]"></p>
  <p>Hero's Biography: <input id="member3_bio" type="text" name="team[hero][][bio]"></p>
  <button type="submit" value="submit">Submit</button>
</form>

and my tests were all passing.

I also realized today that I’ve been achieving the end goal of clearing out hashes without using the method provided by Ruby. When I read:

Luckily for us, there is already a Ruby method for emptying a hash: #clear.

I thought to myself, “Whoops!” because I’ve just been resetting hashes & arrays by doing @session = {} or @@all = [] up until this point. I haven’t checked the docs yet to make sure this method applies to arrays as well but I feel like I’ve seen it used so I’m relatively confident in that. I guess I’ll find out the first time I use it.

Time spent today: 6:37
Time spent total: 165:06
Lessons completed today: 12
Lessons completed total: 392

Do recruiters make you mad? What’s your advice?

So nested forms aren’t as bad as I thought they would be. I guess it helps that I had some good teaching before I got into it. I think I had the longest video yet to watch tonight and that took up most of the time once I finished the lab I started last night. The lab I’m on seems to be more of the same just getting the concept to stick with a more in-depth nested form. It has an option to persist the data AFTER getting the tests to pass initially. I’m not sure if I’ll attempt it or not. I know I’ll need to know the skill but does it help me more to struggle now and be a little quicker later? Or just struggle later one time? I know doing it more is definitely better but there are concessions I make in the interest of time.

Learned a good workflow for building an MVC app that uses a database. First start with the DB, then work on models, then controller routes, and finally the views. I had thought working in the other direction would make more sense but I’ll try what the lecture taught. My thinking is, I start with a view so I know what I’m trying to display, I’ll have my endpoint even if it doesn’t work. Then I’ll build the route that will fill in that view. Then I’ll build the model for the controller to use. Then build the database knowing the full amount of things I’ll need. This is how I thought I did the CLI Gem project where I started with the lowest level and worked my way out with stubbed data to get a final point where when I had real data it just worked. This might not be the best workflow when dealing with things like databases and controllers though. There might be things outside of my control that could end up creating a whole rewrite which would be very sad.

I put in a resume for a Jr. Dev (or was it Jr. Analyst?) role today and the recruiter called me back. To my surprise saying they work with a few companies that take boot camp grads. The main thing I was told is to finish and get that official certification or diploma saying I finished then we could talk. It’s nice to already be connected with someone even if it turns out to be nothing. While I’ve worked with recruiters in the past and never received an offer through any assistance they’ve given I think any interview is a good one for me moving into a new field. The questions and format will be something completely different from what I’m used to. As much as we all wish interviews could be nailed by the best candidate every time they just aren’t and interviewing is a skill in and of itself. I’m interested if there are any others out there that have used recruiters to land Junior level positions and what they thought about the process in hindsight?

Time spent today: 2:44
Time spent total: 158:29
Lessons completed today: 2
Lessons completed total: 380

How to Take it Easy Sometimes and Still Win

I only got a little bit of coding done tonight by choice. I think I’m procrastinating on this nested hash forms lab because nested hashes can get confusing. I started it though and just got sidetracked. I need to stay focused. I worked on getting RubyMine installed to see what it’s about and my computer froze. After that, I just gave up on coding tonight. I guess I wasn’t very motivated if that’s all it took lol.

However, I went to a good Ruby meetup tonight and got home late and am just distracted. I went to the Nash.rb 2nd Quarter Social tonight and hung out with people that are in the Ruby community here in Nashville. It was laid back and I just spoke with a bunch of people. A guy named Sam who just moved to Nashville last month and has 3 years of Rails experience yet went to Law school. Chris who graduated from The Iron Yard‘s Front End program in December and is just interested in Ruby. Pete who’s a VP at Takl who are looking for a Senior RoR’s dev. Jon and Jim who are both 10+ year devs who talked about their company but never named it. I was able to look at the Meetup RSVP list and then check LinkedIn to see they work for Groups360. Their company interested me because they’re looking to provide a SaaS product to the hospitality industry. Ty who works for Kindful and is somewhat jealous that he had to get a CS degree (75% of which was useless he said) because boot camps didn’t exist when he started. I don’t know if it’s the nootropics I’m taking or if I consciously made sure of it but I remembered every person’s name I met tonight and was able to say goodnight to them by name as well. This typically doesn’t happen.

I found this meetup to be much more interesting to me than the previous ones I have attended. I think it’s because we were interacting well and I was able to speak with all different levels of people. I’ve found there is A LOT of JavaScript around, and for good reason, so it as nice to speak to people who knew the things I’m currently learning. I’m looking forward to the Nash.rb meetups in the future. I’m sure I’ll get back to enjoying JS meetups as well as soon as I get to the JS curriculum and get back to that.

Time spent today: 0:33
Time spent total: 155:45
Lessons completed today: 0
Lessons completed total: 378

Sinatra, models, views, controllers, and erb, OH MY!

yield sign

Sinatra, and models, and views, and controllers, and erb, OH MY! Tonight I kept building small things with Sinatra. I’ve realized exactly how the MVC system works and what each piece does. The model is all the ruby classes I’ve been writing. The view is a mixture of HTML and Ruby that the user sees in their browser. The controller takes the user input and returns the data that has been crunched by the models. Now that I’m creating the route to a URL, creating the form on that page, sending the data that’s input back to the controller, having it sent to a model, having the model return it to the controller, having the controller retrieve a new view and send it to the user, it all makes way more sense. LOL.

One thing I think will be a big piece but was only touched on for a moment was yielding.

Let’s say we have a controller action:

get '/' do
 erb :index
end

When the above controller action is triggered and the erb method is called, it looks to see if there is a view titled layout.erb. If that file exists, it loads that content around the desired erb file, in this case index.erb.

The way the layout.erb will “wrap” the index.erb with its code when a <%= yield %> is inserted seemed like something important. Yet, I have yet to use it and I’m more than a few lessons past the readme that showcased it. Oh well, that’s one of the reasons I write about things here. So when I need to find it I know where to look.

Time spent today: 2:17
Time spent total: 155:13
Lessons completed today: 6
Lessons completed total: 378

Sinatra is Moving Along

fire and smoke

Sinatra is moving along and clicking well. I have this fear after being somewhat cocky in last night’s post that the spirits of those Senior Devs before me are going to jump into my learning and humble me some. If so, not today. It’s all making sense the first time through. I think this is because there’s very little new logic. It’s just where to put that login in regards to models, views, and controllers. Like, if I’m going to use ruby in a web page the page with be index.erb so it can be interpreted and I’ll have to wrap code in <% %> or <%= %> depending on what I’m going to do with it.

The largest piece of info I learned outside of more of the Sinatra DSL is how params work.

If you are unfamiliar with the params object and how it relates to form and inputs, that’s totally fine. The TL;DR is that all the information the user submitted in the form is available to your code within a hash named params.

So for form data, for example, let’s say we have <input name="username" value="" /> and the form has an input box and in that box is withloudhands (I don’t know why the curriculum chose this as an example lol). withloudhands is now the “current value”. Let’s say there’s also an email input which I won’t paint the picture of. The params hash after this is submitted would be {username:"withloudhands", email:"[email protected]"} and this hash can be used just like any other hash. So params[:username] would return "withloudhands". I did notice that the hash stores everything as strings so when performing math operations I had to utilize the .to_i method.

I also learned that controller actions never care about their return values. This came up when a student suggested using #tap in a lecture and Avi said that while it would work he didn’t think it was the best option. I still haven’t dived into what #tap actually does even though I’ve discussed it with Mike in the past. I did come across a great, and quick read, blog post “Block, yield, tap” by the more studious Rachel Walwood who’s also going through Flatiron right now. She goes through exactly what it is in a solid and concise manner.

Time spent today: 2:19
Time spent total: 152:56
Lessons completed today: 7
Lessons completed total: 372