DEV Community

Cover image for A Sinatra MVC Application for Storing Quotes
Guosa
Guosa

Posted on • Updated on

A Sinatra MVC Application for Storing Quotes

My objective was to build a Sinatra application which met the following requirements:

  • had a MVC (Model-View-Controller) architecture

  • used ActiveRecord

  • utilized multiple models

  • used at least one has_many relationship on a User model and one belongs_to relationship on another model.

  • had user accounts, where users were able to sign up, sign in, and sign out.

  • validate the uniqueness of user login attributes, such as username or email

  • once logged in, a user had the ability to create, read, update and destroy the resource that belongs_to that user.

  • ensured that users could edit and delete only their own resources but not those created by other users.

  • validated user input so bad data was not able to be persisted to the database

I was able to create a working Sinatra MVC application which met all of these requirements. I decided to make my application function as a quote management service, where users could enter memorable quotes that they had come across and save them in their pages, while also being able to view quotes that other users had saved.

I learned a great deal about a number of features of Sinatra and about programming in general.

Some specific things I gained more experience and knowledge of were the following:

  • how to design views (the V in MVC) to make my application's pages convey relevant information to users based upon what links or buttons they clicked and whether they were logged in or not.

  • how to make good use of helper methods.

  • the usefulness of yield and layout in reducing repetition of code

  • the usefulness of embedded ruby tags

  • the power of controllers (the C in MVC)

  • the usefulness of validations on models

  • sessions and how to use the bcrypt gem for user authentication

  • forms and how they relate to controller actions

I learned a great deal about Sinatra and working on this project was a rewarding experience overall.

A link to the repository for my project.

Top comments (0)