this. & Model, singular & [Mark] Haml

PUBLISHED ON DEC 11, 2013 — IMPORTED FROM TUMBLR, TEXT

Day 19 of MakerSquare.

Frontend: We started with a much-needed refresher in Javascript. After Gilbert had us all repeat “‘this’ points to the object calling the function” not once, but twice, I decided to write it down. It could be important. </understatement>

As an aside, will the next generation understand jokes referencing closing HTML tags after we all start using Haml and other templating engines in the Future?

Anyway, we broke for lunch before getting into `for` loops. Met up with a friend of mine who wants to develop a game to teach kids programming concepts. Luckily, I could follow along with his idea and even understood the funny stories he told about his CS undergrad experiences in the lab. At the very least, I’ll be a much better guest at cocktail parties after this program is over. 

Backend: We got back into ActiveRecord and associations in Rails. During the hackathon, we almost used multiple tables and started to dive into `has_many` and `has_many` relationships [versus `has_many` and `belongs_to`, which is all we’ve learned so far]. Thanks to our Saturday night tech pivot, we didn’t have to worry about any of that quite yet. 

Back to Rails. I thought I had understood what gets pluralized and when in Rails. But when I was stumped by my pair’s question of why models were singular when reference in the Rails console, we had to get a response. The first part of my takeaway was

Model != database

Since learning about models and databases/tables on the same day last week, I’ve been using the words interchangeably. If they all meant the same thing, then why, in the Rails console, did we write `Movie.all`, and then pop over to Sublime Text to examine the “movies” table in the schema?

As I grokked it, the model isn’t the whole database, it’s a representative portion of the whole database, like a row. A complete [or incomplete] row can tell you what the column headings are and what data type is accepted. From this information, it’s possible to build out the database and ready it for accepting content. hashtag rails magic

I worked on the Haml lesson at home, even though I continuously thought of this guy whenever I read the name of the templating language. I already hit some snags with not indenting a table’s body and trying to find reliable documentation for writing `form_for` forms. I get a badge for those things, right? incomplete documentation achievement unlocked 

That’s enough of that. I’m going to outline [read: stare at] my hackathon write up. Hope to see yinz at the holiday party tomorrow, especially the bots that follow this blog.

As an aside, I’m going to strongly encourage the use of this thing during the next hackathon. You know, for the yuks.