I Finally Finished My First Website!
Tags: beginners, html, sinatra, crud
Published: 2021-04-06 22:57:02

After what feels likes forever to me, I finally finished my Sinatra Project. I can finally say I have OFFICIALLY made my first website, how exciting is that!   

The idea behind my website is that the user loves to travel so they have a bucket list of all the places that they want to travel to. So on the website, they create their account and are allowed to create travel destinations that they wish to go and can take notes on those specific places. The notes include the name of the destination, a description of that place, and a rating from 1 to 5 stars. Once they have traveled to that place they can either edit it to say they have checked it off of their bucket list or can simply delete the place from the list. 

I started my project by creating migrations to create my schema. One of the migrations I ran was
rake db:create_migration NAME=create_travel_destinations.rb 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zashgo0v73ztrl5u7fzx.png)

As you can see, in this file I used the create_table method to create my travel_destinations table with columns called location, description, rating, and user_id. 

I then continued on with my models. I create my classes and had them inherit from ActiveRecord::Base. The last thing I do in the class is give them Active Record Associations. 
Now that was the easy part. Creating the controllers and views files is where all the fun is at. 

Here I show my application controller, which is also the parent controller (or we can say, the main one). 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yv3vfecygwe79xfybiel.png)

In my parent controller, I have a configure block that is used to make sure my views or erb files will show, that the data for a specific user is saved by enabling sessions, and finally set those sessions secret by using an ENV file that contains an intricate string. I also render my welcome page here, although if I wanted I could also add it to one of my other controllers. Instead of setting my routes and rendering my erb files here, I simply have helper methods to make the rest of my code more DRY. 

DRY: DON'T REPEAT YOURSELF

As long as my helper methods are created in the parent controller and all the other controllers inherit from the parent controller, the helper methods can be used. Making my code for CRUD more DRY. 

CRUD: CREATE, READ, UPDATE, DELETE 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g2we9nft3tgtfi09fjs8.png)

Here I am showing my READ all route. It has my helper method redirect_if_not_logged_in and right below that I set an instance variable equal to the current user and all travel destinations. Which then is rendered to the erb file travel_destinations/index. 

The last thing I want to mention is that the erb file will be what the user can see in the browser through forms that will require their input. Anything that I want the user to see will be set in html code and/or erb tags to see or evaluate ruby code. 

Finishing this project was tough, but it only made me feel that much closer to getting to the finish line.