Creating a Social Media using Sinatra

Alex H
3 min readMar 7, 2021

Using Sinatra to create a social media page was both interesting and frustrating at times. From previous work I was familiar with the Ruby code that would go into the application, but the database management, HTML, and CSS code became the main focus of improvement for this project. Below I have focused on a few topics that came up while building my webpage.

Creating a Database Table through Migrations:

As stated before I am decently comfortable with Ruby code, but database management was a completely new skill for me to learn. In this project I used ActiveRecord to create tables in my database through migrations that I wrote. To enable ActiveRecord for my project I needed to add the proper gem to my Gemfile, then run Bundle Install.

ActiveRecord allows me to store and retrieve properties and relationships of objects in my application without having to write SQL statements.

Next, I need to create the migration for my users table in the console:

This creates a new migration in my database folder for use. Now, I need to navigate to the migrate folder and structure the table with Ruby code:

This example is the users table in my app.

The above code structures the the users table with a username that will be a string, an email that will be text, and a secure password that will be a string as well. Finally, I need to actually migrate the table into the database in the console:

This updates the database with the migration created and now has a users table with the above schema.

Using Google to better my project:

I think what really took my app to the next level was using Google to search for solutions to issues I ran into throughout the building of the webpage. In my previous work I did not use Google as a serious resource when I ran into problems, and it made a world of difference. The biggest help Google gave me was styling my webpage with CSS. I do not have much experience with HTML or CSS and was able to search different ways to change the look and layout of my app. This both made my project look fantastic and increased my knowledge of HTML and CSS in the process.

These are only a few things I learned throughout the two weeks it took me to create this application. I am excited for what the future will bring as I learn and develop my skills more.

--

--