w4d1 - Oh CRUD!

    Today we officially began our quest to master Rails. It seems like a daunting task, but every journey starts with just one step. We spent the latter part of last week preparing for the journey, and it seems to have paid off thus far.

    I thought today went pretty well and I’m beginning to understand Rails more and more each time I look at it. Today was all about setting up Routes and configuring controllers to handle those route requests. To do this we spent the day setting up a simple Contact Sharing API that was able to store a users contacts and then allowed the user to share those contacts with any other users. This project also introduced us to the concept of an API, which, from what I gather, is a very broadly used term. In this context, we were providing raw data (rendered as JSON objects) via specific routes that could be hooked into from a separate program. We learned that this is actually similar to the way that popular applications like Twitter and Tumblr handle API requests, which is what allows independent developers to build applications or web parts surrounding those elements.

    We also learned about the importance of designing with CRUD in mind. Create, Read, Update, Destroy. If you can design your sites resources using just these actions, then you should be able to produce a RESTful, (REpresentational State Transfer) application, which is all the rage these days. That basically means that the application should work in such a way that doesn’t expose the inner workings of itself to the client. A person interacts with their browser, the browser interacts with a web server, and the server takes care of everything and lets the browser know how to proceed. This isn’t the olden days anymore (like pre 2000!)

w3d5

  Week 3 done! And it did NOT go down without a fight. It was a sort of roller coaster of a week. It started with the universally despised SQLZoo, climbed to a high point on Wednesday and Thursday where we got to start experimenting with Rails and ActiveRecord and then plummetted back down to Earth as we ended the week trying to reconstruct ActiveRecord, at least partially. Even so, Active Record Lite was not so lite. It was definitely a difficult task, one that most of us did not complete by the end of the day… oh and did I mention that it was a SOLO day for everyone? That always ramps up the difficulty a few notches. I would have to say that this was the hardest day yet… BUT after all of this, I can now appreciate the beauty and elegance of Rails and ActiveRecord, and I feel like I have a deeper understanding of what might be going on under the hood, and THAT will inevitably make things easier to understand down the road hopefully…

  We were also introduced to the concept of metaprogramming, using the ability to Ruby to inspect itself to sort of redefine the things it can do dynamically. I’m sure that was a pretty fuzzy explanation, but hey, it;s a pretty fuzzy subject! Basically it allows your code to write it’s own code, which is a little mind blowing, right? I’m pretty sure it eventually leads to Skynet, but it’s fun to play around with for now, and seems like it’d be a pretty powerful tool to master. I think part of what made Active Record Lite so difficult was the fact that we had to utilize metaprogramming to get the results that we wanted, which isn’t easy when I only just learned about it the previous night. I’m sure it will all make more sense after using it some more, and maybe watching the Terminator movies a few more times.

  Today was also the last day for the students in the previous cohort. It was awesome seeing how far these guys (and gal!) got in 12 weeks, and I was able to see the kinds of things that I’ll be able to build pretty soon. At the same time, it feels like a long way off considering that we haven’t exactly tackled any major projects yet. I’m not saying that what we’ve done up to this point hasn’t been pretty cool, I mean we started 3 weeks ago with very little knowledge and are are a few short weeks away from being able to build functional web applications. I can feel us turning the corner as we dive head first into the Rails curriculum for the next 2 weeks.

  Towards the end of the day, App Academy held a “hiring day” where people from potential employers came and the graduating students could show off their Final projects. It also gave me a chance to talk to some of the grads, which is something we never really get an opportunity to do, considering we all spend most of our days buried in code. It was nice to get some perspective from students who were just where we were 9 weeks ago. It was also a good opportunity for our class to get to know each other better outside of normal class conditions. We even joked about what it would be like if WE also had to show our projects to the employers…

"Uh ok, first go the terminal and clone my repository from Github. Now type ‘g = Game.new… OK now type g.run… Oops, I guess it’s g.play. Oh there it goes! Oh wait, I forgot that you have to install a few gems first… Ok, now we’re ready, just type g.play! …no, sorry, there’s no cursor, just type in the commands… No, don’t type that, it’ll error out! …it’s pretty good right?!"

w3d4

class TumblrPost < ActiveRecord::Base
  validates presence: true

  belongs_to(
    :author,
    class_name: “User”,
    foreign_key: :author_id
    primary_key: :id
   )
end

class User < ActiveRecord::Base
  validates presence: true, uniqueness: true

  has_many(
    :posts,
    class_name: “TumblrPost”,
    foreign_key: :author_id,
    primary_key: :id
  )
end

  Today was all about associations. We also did some associations, and to end the day we finished up with a little bit of association creating. All in all, I’d say we’re getting pretty good at associations!

  Rails continues to be magic, but we are slowly learning how the Wizard works. Sometimes however, there are things that just make you scratch your head. Today we spent about 20 minutes trying to do something the “long way” by making associations, when we could have just chained a few methods together. We figured it would be good practice to do so. We ended up creating a ‘has_many :through’ association that went through another ‘has_many :through’ association. Well apparently, that’s when Rails stops doing things magically because we were unable to get the method to work properly. After calling the TA over, we found out that for some reason, when you chain two ‘has_many :through’ associations together, the association won’t work properly unless the record you are using is already saved in the database. So, even though we had methods that worked perfectly fine when used separately, they broke when we tried chaining them together. I’m sure those are the kind of things you learn over time, and might be able to make sense of at some point, but for now it just seems a little odd.

  It’s a good thing that we spent the last couple of days getting well acquainted with ActiveRecord, because tomorrow’s task is to build our own version of it, solo!

w3d3

Rails today! It was crazy seeing all the things that we manually constructed this week being automagically handled by Rails. It was pretty amazing. Today was mainly focused on getting used to how to do database migrations, and creating associations between models. This is going to be a crucial concept to master and today was a good start at getting our feet wet in the world of Rails and ActiveRecord

w3d2

SQL part II today… the sequel. It actually wasn’t that bad! Of course we all realize now that the awful SQL setup they had us working through the day before was partially to give us an appreciation for well written, properly set up databases and how much easier it is to query.

We worked on integrating SQL into Ruby today to build a database driven application and after the previous day, it was much easier to write and understand the SQL needed to do so. Looks like we’ll be moving right into Rails tomorrow and utilizing ActiveRecord to do most of our database querying. I’m definitely interested to find out how much more it will all make sense after having looked at a ton of SQL these past couple of days