My Sinatra Application
Published: 2021-02-15 16:41:01

My second project requires use of the Sinatra Framework, which I utilized in order to create a customized Among Us character creation app in which the User is prompted to create a custom Among Us character complete with name, age, abilities, and backstory.

The requirements for the project were relatively straightforward, to create two models (one of which is to be selected by the creator, the other being the User model which must be able to signup, login, create, edit, update, and destroy a portion of the first model).

Additionally, the Restful Routing convention was supposed to be used in order to provide a clean template for any future edits to the application, and likely more importantly, setting a structure for any future applications to be built.

My application was focused on the ability of the user to create a personalized Among Us character, and have features in my application that make the user's interaction with the application feel customized.  

I was having difficulty distinguishing my user's interface when they were/weren't logged in, so after a bit of research I discovered that utilizing a macro for determining whether a user is logged in or not, I can simply create an "if/else" statement to determine what the user can view, shown as follows:

    <% if logged_in? %>
      <div><a href="/">Home</a></div>
      <div><a href="/characters">Characters</a></div>
      <div><a href="/logout">Logout</a></div>
    <% else %>
      <div><a href="/">Home</a></div>
      <div><a href="/logout">Login</a></div>
      <div><a href="/signup">Sign Up</a></div>
      </div>
    <% end %>

By creating the "logged_in?" shortcut, which ultimately just checked if the User could find their user id within the current session, if the User was found, they would be directed to the Home page to go to either the index if they chose, or alternatively, they could logout.  

However, if the logged_in method did not find a current User id within the Session, they would be redirected to the login page with the option to login or go to the signup page.

I used Active Record in order to make my database accessible and make the CRUD operations simple with the pre-defined methods that Active Record provides.

I also started my application with the Corneal gem, created by a previous Flatiron student, in order to make my Model/View/Controller format pre-defined.

Unfortunately, I am not great with CSS or HTML, so I was really learning on the spot to try and incorporate some features and stylistic changes into my application, but I ultimately found that an interactive background showing the website appearing to be in space along with a few color/size changes would have to suffice for the time being (although I will be adding additional features and changing the appearance of this application as time goes by).

Lastly, in order to ensure that a User can only edit and/or delete his/her character, I had to use Validations which also does away with any concerns of URL manipulation (which I originally struggled with).

Other than utilizing the bcrypt gem with a secure password for each user, this application was set up in the above manner and will be improved as I learn how to implement more advanced features.