Building our own IMDB

I am now 5 weeks into The Starter League and I still love every minute of it.  At times I find it hard to believe that it has only been 3 weeks since I worked with Rails for the first time.  It has empowered me to do things already that I thought would be impossible after only 5 weeks here.

In the last two weeks we have spent a lot of time working with databases.  First we’ve learnt how to make two databases relate to each other by adding a foreign key to one of them.  You call that one to many relationships, since you have one ‘object’ that relates to many others.

SMDB movie index page

The list of Movies on our SMDB app – our own IMDB clone

To explain this concept and give us something to work on, Raghu made us build a copy of IMDB (Internet Movie Database). For the sake of our project, we assumed a movie could only have one director.  So one director could have many movies but a movie could only have one director. This was our first one to many relational databases.  We achieved this by adding a director_id column to the movie table in our database…. that sentence would have made no sense to me a month ago!

We then added another one to many relationship by adding roles to a movie (again assuming a role could only be in one movie).  But since a role is played by an actor, we could add another one to many relationship between a role and an actor.

SMDB Movie Show page

The details page of my Favourite movie, The Shawshank Redemption on our IMDB clone

After we did that, Raghu explained that we in effect had created a many to many relationship between actors and movies by using a table linking the two, in this case called roles.  So we had created our first many to many relationship without even knowing it!

Raghu also challenged us to build a paging system after one of the classes this week.  I struggled with that one for a few hours but eventually I was able to get pagination going the way I wanted it without using a gem. A gem is like plugin, a piece of code somebody else wrote, usually for a task that many people want done. You install the gem and then you can use it instead of writing that part of the code yourself.

pagination on smdb

Doing pagination far a fun challenge, here it is nicely implemented on our IMDB clone

On Friday we’ve also learnt about font awesome, another little arrow now in our arsenal.  It allows you to add icons to your site that act like fonts, so you can change the colour, size and some other properties in CSS like regular fonts.  No need for a designer to redo everything a 100 times!

Building a IMDB clone was great fun! I continue to be amazed how much fun it is learning to code. I really look forward to using these new skills to solve meaningful problems in the future!

Comments

comments