Partials are coming together more and I have to say they’re pretty sweet. Rails does some automagical stuff that I can’t completely wrap my head around just yet. However, I probably won’t be able to for a while as the people who created it are WAY smarter than me. However, as an example there’s this sequence of things that Rails does:
<% @posts.each do |post| %> <%= render :partial => "post", {:locals => {:post => post}} %> <% end %> <!
I don’t know why I thought Rails layouts and templates would be somewhat easy. While in a sense it’s taking snippets and putting them in other files to reuse of course there has to be some logic in there to ensure that the proper data is being shown. So rendering partials with locals is starting to make sense.
For my example <%= render partial: "authors/author", locals: {author: @author} %> - The first key-value pair partial: "authors/author" tells Rails the name of the partial to render.
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 students Slack channel and <20 minutes it was figured out by the group. So you’re probably wondering what it was…
It felt so good to spend almost the entire day coding. I missed it. My progress was VERY SLOW at times (or so it felt). Things like the :source option in Active Record were foreign and not really taught but needed to solve a large lab I was working on starting first thing this morning. Luckily I have access to some awesome help. Here’s one conversation I had today:
Seth Alexander 34 MINUTES AGO
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: