The Pieces Are Coming Together

Feeling great about today. The things that a struggled with the most I ended up cementing (it’s not dry yet) into my brain. The Learn community is awesome I must say. After 2 hours with a Learn Expert (basically a TA), we were both sufficiently stumped. I dropped a note into the student’s Slack channel and <20 minutes it was figured out by the group. So you’re probably wondering what it was…

<h1><%= @post.title %></h1>
<p>
  <%= @post.content %>
</p>
<% @post.categories.each do |c| %>
  <h3><%= c.name %></h3>
<% end %>
<% @post.comments.each do |c| %>
  <p><%= c.user.username %> says: <%= c.content %></p>
<% end %>
<% @post.users.uniq.each do |u| %>
  <%= link_to u.username, user_path(u) %>
<% end %>
<%= form_for @comment do |f| %>
  <%= f.label :content %><br />
  <%= f.text_area :content %><br />
  <%= f.collection_select :user_id, User.all, :id, :username, include_blank: true %><br />
  <%= fields_for :comment_user_attributes, User.new do |u_fields| %>
    <%= u_fields.text_field :username %>
  <% end %><br />
  <%= hidden_field_tag 'comment[post_id]', @post.id %>
<%= f.submit %>
<% end %>

Yeah, it’s in that code… can you find it??? Well, I wrote it and I couldn’t find it so if you can’t all good. If you’re still trying don’t scroll down lol. Here’s the fix with just the line of code that had the error:

<%= f.fields_for :user_attributes, User.new do |u_fields| %>

Yeah, I was missing the f. before fields_for which makes a BIG difference. I can confidently say that I’ll most likely never make that mistake again. I also started taking screenshots during lecture videos of things I wanted to remember and write down. Figured this would be more effective than writing down the time in the video things happen. Although, I did write down a couple larger concepts if I ever need to go back and look.

Something I was struggling with early was collection_select(:post, :author_id, Author.all, :id, :name_with_initial, prompt: true) and reading the APIdock didn’t help. To the Slack channel for people doing Rails I went. Got some solid info. Then later in a lecture video, Avi goes through an almost identical line of code and what it means. Here’s what I got (saved as a screenshot that I’ll write out by hand in my notebook later):

For context higher up in the code: <%= form_for @post do |f| %>
<%= f.collection_check_boxes(:category_ids, Category.all, :id, :name) %>
Will generate a checkbox named post[category_ids][] for each category in Category and it will use the :id as the value for the checkbox and it will use the :name method as the label for the checkbox.

Exactly what I was looking for was right around the corner when I finished the lab. This isn’t the first time I’ve experienced this. There have been many a lecture where after I struggled through something it all became clearer. Specific topics that I had questions about were explained in a way that answered my questions.

Side note, I’ve realized I need something to rest my wrists on. Especially my right hand that uses the mouse. This Microsoft Natural Keyboard has a nice soft wrist rest. However, these 10 hour coding days + this time writing the blog takes a toll.

It’s time for my Sunday night look into where I’m at. I’m 53% done with Rails according to my dashboard and 50 lessons from my Rails projects. I’m still on pace to start my projects on May 10th at a 5 lesson/lab/lecture per day pace. Mon, Thurs & Fri of this past week I spent <1:30 working so if I can get that back up over 2 on weekdays (closer to 3 ideally) and keep this solid 10 on the weekends I’ll be happy.

Time spent today: 10:11
Time spent total: 242:14
Lessons completed today: 9
Lessons completed total: 466