Second Project
My how time flies when you’re coding! My second project is at an end and I would like to share some of my final thoughts as I wait for my review. This project really challenged me I won’t lie. I don’t think I could have ever done this alone, I asked for help countless times. I helped others just as much though. Coding really takes a village and I have a village of great peers at FlatIron School.
Now for how the project actually works. This project uses ActiveRecord and Sinatra to create a database and controllers that we can then use to mount on a local host. Below is a list of gems that are needed to run my project. What you won’t see here is the gem that started it all though. It is used outside the project and was made by a FlatIron graduate. The corneal gem was a life saver and it is used to build your Sinatra project folders, it even includes some CSS styling!
After the project is built I had a little crisis not knowing where I wanted to start with my build. I wound up choosing to start by building my databases. I had to plan out what I wanted my project to be and after some reflection I decided I needed 2 databases. I started with a create_users database and a create_pokemons database. To make my databases I used the rake gem and used the DB:create_migration method. I then added a create_table and populated it.
The next task was getting data for the database. Looking back to the gems we have one called ‘Faker’ and that gem is used to make data! It also already had a pre-made Pokemon data for me to use!
However this project also focuses on CRUD meaning that we need to create, read, update, and delete data. This data needs to be stored with a session[:user] as well so we can only edit data we have made ourselves! This means I don’t have that ability with the databases I currently made. So I had to make a 3rd database and utilize two belongs_to ActiveRecord method. The pokemon created needs to belong to a user, but also belong to the pokemon table. This allows a created pokemon to be assigned to unique user for editing and deleting capabilities.
Lets move on to sessions and logging in and signing up. These actions are handled in the C of the MVC (Model, View, Controller). In the users_controller we have our signup method where we “get ‘/signup’ which will take us to our view page(see second image)
Now that we have an account we have to login and store that login with a session! A session is used to hold data pertaining to one request and storing it so that for future requests. A session is made in the configure block of the Application_Controller, we also have to make sure that our session is not able to be broken into by anyone trying to take our data. This is done by making a secret session with a key that won’t easily be guessed.
I had some fun with this next part! I wanted to get pokemon into a trainers account and let them edit the pokemon the have in their collection. This was definitely very hard for me. I wound up needing a to create a new migration to add a new column in my users table, run a new migrate to update my database, turn that column into an array, then iterate the array to pick a pokemon and shovel it into an @user.pokemon array. Below is the code for each those steps respectively.
There was a lot of road blocks while making this project I had a lot of fun and help from my cohort though! Its great to see how just talking out issues really puts everything in place much faster than staring at a screen alone. I had so many typos scattered around ruining my code that I just kept glancing over. Extra eyes helped me every time. I just want to show you my index page before you go because I’m very proud with how it all turned out!