Day 23 — week 4 (Wednesday)

So, today was really good but really hard. We continued working on our bookmark-manager and as the challenge progressed so did the difficulty. My pair parter and I started the day going over some of what we learnt yesterday, mainly the concept of relational databases and many-to-many relationships. The first concept is about splitting data into tables. Rows in one table sometimes references rows in another table, and they are therefor related. A many-to-many relationship is one of many ways these can be related, and it makes sure that data from both tables can be related to many different rows in the other table. If we take our bookmark manager as an example, we have a table of links and a table of tags. One link can have many tags, and one tag can be related to many links — many-to-many.

We then went on to deploy our app to heroku, which is a cloud-based platform that can host web applications. Afterwords we implemented a tag feature, as well as a way for users to filter links by tags. We created a new Tag class responsible for putting the tag(s) into the tag-table in our database. It’s all done by DataMapper, which we have required in the class. The hardest part were to set the relationship between our links-table and tags-tables. DataMapper creates some sort of array (it’s using [] syntax, but is not an actual array) to store the relational data in, and in our filter-feature we had to specify that only the links related to the filtered tag was displayed. The route looks like this:

get '/tags/:name' do
tag = Tag.first(name: params[:name])
@links = (tag ? tag.links : [])
erb :'links/index'
end

First, we assign tag to the tag that correlates with the parameter :name . Then, if such a tag exists, we assign all the links related to that tag to @links . We then go to links/index which displays @links .

Next thing to implement was the sign-up feature. We created a form asking for email-address and password, and this data is again handled by a User class and stored in a users-table via properties in the class. Properties are just class methods, and can be called on classes themselves (vs. instance methods which can only be called on instances of the class). We made it as far as to encrypt the user-passwords using BCrypt, and by the time we were to set up a password confirmation feature, we decided to call it a day as productivity had declined a fair bit. Tomorrow is a new day with a fresh mind, and I feel like we made a bunch of progress today. I am definitely understanding the concepts of databases much better than yesterday!

What I learned today:

  • Deploying a web-app to Heroku
  • Setting up different environments (i.e. ‘test’ and ‘development’)
  • Setting up a Rakefile
  • Better understanding of databases

What I want to focus on tomorrow:

  • Taking time to deeply understanding the material
  • Understanding password encryption
  • Understanding how our model manipulates data in our database
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.