I’m going to be very happy to code during the day tomorrow. I’ve been tired these last few nights during my target of 8pm – 11pm coding time. I just took a second, leaned back in my chair so my head could rest on the chair back, closed my eyes to think about a problem, and almost fell asleep.

Learned about some Active Record Callbacks of which there are many more than I would have imagined:

  1. Creating an Object
    • before_validation
    • after_validation
    • before_save
    • around_save
    • before_create
    • around_create
    • after_create
    • after_save
    • after_commit/after_rollback
  2. Updating an Object
    • before_validation
    • after_validation
    • before_save
    • around_save
    • before_update
    • around_update
    • after_update
    • after_save
    • after_commit/after_rollback
  3. Destroying an Object
    • before_destroy
    • around_destroy
    • after_destroy
    • after_commit/after_rollback

That’s all. Goodnight.

Time spent today: 0:56
Time spent total: 222:27
Lessons completed today: 1
Lessons completed total: 450

I’m exhausted tonight. Been working mainly on more Active Record Associations. More complex ones than before I would assume to get in practice for later labs. Foreign key and Class Name Active Record class methods to be exact if you’re looking for some light reading lol.

I attended an Alumni career fair at my alma mater Belmont University today which was interesting. I never attended one as an undergrad so the whole, drop your resume off on as many tables as possible, was lost on me. I did get a chance to chat with more than a few HR people and get some leads. Nobody was actively hiring Junior Developers but I’m not job ready yet so that’s fine. I’m getting on the radar and will follow up with all of them tomorrow when I can actually type without errors. Also, the FBI recruiter informed me I should apply to be an Intelligence Analyst.

The more fun thing I did today was attend The Iron Yard‘s Spring Demo Day for their current graduating class. It was fun to see people’s projects and learn more about how they built them. I saw some neat stuff. It was also interesting how The Iron Yard splits their students into Front End and Back End tracks then have them work together on their final projects. A few of the guys I met said they might attend the FCC meetup on May 6th so I look forward to that.

Time spent today: 1:30
Time spent total: 221:31
Lessons completed today: 2
Lessons completed total: 449

Watching Avi build out the TodoMVC is an interesting thing and I’m happy I get to do it as part of my curriculum and showing what Rails does. That was the bulk of the new work I did tonight. Something that I ran into during my Sinatra project was getting all my associations to work properly. I had issues because of what I now know is called the Active Record Inflector. Now I have this handy table in my notebook:

Name Data
Model Author
Table authors
Foreign Key author_id
belongs_to :author
has_many :authors

This is going to make life easier, although, I’m pretty sure I’ll be building most of my migrations using generators in Rails. However, I’ll still have to fill in my models so this works as a helper for sure.

So… I went to a meetup tonight. I pretty loose one where we all just hung out and worked on whatever we needed to. I decided to work on making my Sinatra portfolio project even better. The largest thing I realized was that I hadn’t implemented authentication checking when people log in. So, I was checking that the username matched one in the db but I wasn’t checking to make sure the password was correct.

post '/login' do
  @user = User.find_by(username: params[:username])
  if [email protected]
    session[:id] = @user[:id]
    redirect 'houses'
   redirect 'login'

So I added that in 🙂

post '/login' do
  @user = User.find_by(username: params[:username])
  if @user && @user.authenticate(params[:password])
    session[:id] = @user[:id]
    redirect 'houses'
   erb :'users/login'

I also realized that this will not give me any errors when the password is incorrect. At least not in the @user.errors way that I was getting errors due to validations not passing. I had to figure out a way to display a username/password is the incorrect message but only when the login fails. I solved that in the view.

<h1>Please Login:</h1>
  <% if [email protected] %>
    <h3 style="color:red">Incorrect username or password.</h3>
  <% end %>

I still have some UX things to add in so navigation is easier from page to page instead of all of it happening for the most part from dropdowns in the navbar but I’m pretty happy with where the app is at now for being in my portfolio.

Time spent today: 2:59
Time spent total: 220:01
Lessons completed today: 2
Lessons completed total: 447

Not much going on but completing a couple larger labs tonight. One significant thing that halted me for a while was an issue in my strong params. I had:

def song_params
  params.permit(:title, :released, :release_year, :artist_name, :genre)

Which looks really nice but doesn’t take into account that I’m using form_for and thus my submitted data is actually a nested hash. A quick change to:

def song_params
  params.require(:song).permit(:title, :released, :release_year, :artist_name, :genre)

Had me moving along again. That’s all I have the energy to type tonight since my 4-month-old had me up at 6am this morning.

Time spent today: 2:38
Time spent total: 216:21
Lessons completed today: 2
Lessons completed total: 445

I can happily say that I got zero, yes 0 coding done today. Well, I guess I got a little in during my 45 minutes Sinatra Project review this morning. Which was a great review btw.

Hi Seth,

Awesome job on your Sinatra Project!! You did a great job, and I really appreciate your work on the Active Record relationships and your clean and concise code. As you move forward these practices will help you a lot.

Please reach out if you have any questions or concerns as you move through Rails.


A couple things that I shored up/added this morning were Active Record validations for uniqueness on username and email when someone signs up as well as displaying error messages on the sign-up page.

Why am I happy about this? Well on Sunday night my wife and I attended a brief marriage seminar. Just something to provide us with tools to communicate better (something most marriages probably need). Tonight we utilized the take home (a fridge magnet) and had a good conversation. So what does this fridge magnet say? It’s the “Speaker-Listener Technique”.

The Floor
Speaker-Listener Technique

Rules for the Speaker:
1. Speak for yourself. Don’t mind read!
2. Keep statements brief. Don’t go on and on.
3. Stop to let the Listener paraphrase.

Rules for the Listener:
1. Paraphrase what you hear.
2. Focus on the Speaker’s message. Don’t rebut.

Rules for Both:
1. The Speaker has the floor.
2. Speaker keeps the floor while Listener paraphrases.
3. Share the floor.

Needless to say, this concept worked very well tonight for my wife and I. It’s designed for times of conflict but we just used it for a normal conversation. Because of this, I’m happy I missed out on coding. While I miss it I know what’s truly important during this short life and a few hours of Rails is not #1.

Time spent today: 3:52
Time spent total: 213:43
Lessons completed today: 12
Lessons completed total: 443

So that intense lab I was talking about yesterday… it took no time at all because of Rails. It was AWESOME. One of the things I learned today that is going to make life easier and ensure DRY.

# example_controller.rb

# Insert at top of controller
before_action :set_example, only: [:show, :edit, :update, :destroy]

# Insert at end of controller

def set_example
  @example = Example.find(params[:id])

So up until now to access a DB object as an instance variable I’ve used the ID passed in from the URL or form and then done a lookup to set the instance variable. That means my code was exactly the same and in four different methods. I always thought this was clunky but didn’t look too hard into how to change it. Now I have a way. So before_action is telling the controller before the action (method) happens to do this. However, only: for these [:show, :edit, :update, :destroy] actions. What do we need to do? That’s right, the :set_example action which is then accessible to the listed actions. So the instance variable is available for each of those views. Check out Filter on Rails Guides.

I also learned the difference between PATCH and PUT:

  • PUT has the ability to update the entire object.
  • PATCH updates only the elements that were changed. Therefore this is the preferred method because of lower overhead.

I realize it has only been 4 days since I started Rails but I like taking a snapshot of where I am and where I want to be on Sunday nights. According to my dashboard, I’m 32% ( 37 / 113 ) done with Rails. I must’ve counted wrong or things have been added because I counted 104 total plus 3 projects. Either way, I think I’m well on my way to hitting the projects starting May 10th which would take a <5 lessons/day pace.

Okay, I have my Sinatra Project review at 7:15am so I’m off to bed.

Time spent today: 3:52
Time spent total: 213:43
Lessons completed today: 12
Lessons completed total: 443

It was a LONG day on my computer. Ubuntu decided to suggest I update to 16.10 and I did. Well, that just started a string of issues that ended up in me reinstalling 16.04.2 LTS. I lost my entire morning and early afternoon to this process before I could get coding today. I’m sure I could’ve figured it out in time but time is something that is precious and I really had no need to upgrade. I’m on a LTS and things work which is all that I need.

In addition, Rails has presented some interesting problems that I’ve either figured out with Learn Expert help or on my own. Here are some examples, that I hope will help students behind me.

This error has persisted since before Rails but I never mentioned it (I don’t think):

An error occurred while installing json (1.8.3), and Bundler cannot
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.

Figured out the best way to fix this is to delete the Gemfile.lock rm Gemfile.lock then bundle again bundle install and that install json 1.8.6 at this moment in time.

Now when you get this error:

/home/seth/.rvm/gems/ruby-2.4.1/gems/activesupport-4.2.5/lib/active_support/core_ext/numeric/conversions.rb:124:in `block (2 levels) in <class:Numeric>': stack level too deep (SystemStackError)

It’s a Rails issue. The easiest fix is to change the version of Rails in the Gemfile. I simply do gem 'rails', '5.0.2' then run bundle update and this error is fixed. I’ve gotten really good at nano Gemfile, do the edit quickly (rails is typically in the first 5 lines), then CTRL + X, Y, Enter, bundle install.

Another interesting error that has popped up on multiple occaisons is:

NoMethodError: undefined method `last_comment' for #< Rake::Application:0x007ff0cf37be38>

To fix this one another Gemfile edit must be done. Simply change, or add in, gem 'rake', '<11.0'. This is just an issue with rake past version 11. I didn’t read up on what it is exactly I just found this answer quickly and it works.

I do these things pretty regularly these days. I wish the Gemfiles of some of these lessons were scaled back some. There is so much unneeded stuff in them (I think). Also, a lot of the versions could be updated to take advantage of more recent versions getting rid of a lot of errors. I get a ton of DEPRECATION WARNING messages and they’re a pain.

On a learning note, while I thought form_tag was cool I had no idea about form_for when it comes to ActionView. Mind is sufficiently blown with how much more efficient this makes things and how much less coding needs to be done for the mundane form building. Also learning how to block CSRF attempts was an interesting bit of info. Cross-Site Request Forgery that is. One site making a request to another site via a form is the general flow of a CSRF.

These labs are getting intense too. The lab I’m currently on is equally or more complex than my Sinatra Portfolio Project which is saying something. Granted, I have been introduced to Rails generators so I won’t have to write EVERYTHING from scratch so we’ll see how it goes.

Time spent today: 5:08
Time spent total: 209:52
Lessons completed today: 11
Lessons completed total: 431