DEV Community

loading...

Sinatra Project

swislokdev profile image Swislok-Dev ・2 min read
I wrote my first Sinatra web app. It doesn't do too much other than allow the user to create an account through username, email, and password creation. The main purpose was for the user to create a registry of all the pets that they own. This gave the chance to explore how a database was created and how information is able to be stored separate from other users as well as learning more about associations. 
Associations are how one about object (the user) is related to another in this case was a Pets class object. The User class was able to hold a has many relationship with the Pets class allowing for more than one pet to be associated with a user (aptly named the owner). The pet in question was only able to be to paired with a single owner as it held a belongs to relationship with the user. A foreign key was used to connect the user to the pet.
With that in place I was able to produce information about any pet that was created by a single user and through the use of the authenticate method to ensure only the owner was able to view this information. The said information only contained the pet's name, species, and age. This leaves plenty of room put in additional details such as a breed, traits, notable qualities, a pet "bio" if the owner so wished it. I had particular issues with creating error correction during the section which the controller would be to blame for this, but possibly due to a missed commit on this single file which gave me troubles. A couple lines of code later and the ability to "view" a pet which did not exist would simply send the user attempting such a search would find themselves back at home with a message noting there is no file.
There is more that I'm hoping that will come with the learning of Ruby on Rails and using MVC more so that I may get the hang of it a little bit more. Sinatra has been that stepping stone into the world of web dev that I've been curious about for so long. Thinking that one must write line-by-line, page-by-page of HTML, thankful that is not the case.
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

pic
Editor guide