Building an MVC Sinatra App

For a school project I was told to build a CRUD MVC Sinatra App that keeps track of something. Here’s the process I went through:

1 — Brainstorming

I decided I wanted to build a workout app that you could use to record your workouts which would consist of multiple exercises which in turn would contain multiple sets and reps. After building my database and models, I learned the hard way that this probably wouldn’t be worth the effort. There were a plethora of problems, but some consisted of:

A) keeping track of around 18 different inputs (1 workout > 3 exercises > 5 sets was the scheme I had decided on),

B) the limitations of only allowing a single workout scheme when this is generally useless for the average lifter, and

C) displaying all this information in an organized manner.

So I ended scrapping that idea and going with a much more basic Movie < User app. A user could keep track of their movies, and look at the movies of other users too. Much easier. I learned a lesson though; figure out everything you can before you start programming. I thought scope creep was a client issue, but I was doing it to my own project.

2 — App Outline

My movie database app has users, who each have a collection of movies. Users are allowed to see others users and their movies, but are only allowed to edit the movie if it belongs to them. I first wanted to make a many-to-many connection, with a user having multiple movies and a movie having multiple owners, but that wouldn’t allow for people to edit movies, only to select whether or not they had them. I decided for this project that movie editing was more in line with what was required, so I went with that.

3 — Building the App

For me, the hardest part of building it was setting everything up. How do I set up and connect to a database again? Where do I enable sessions? The models inherit from ActiveRecord, But the controllers inherit from Sinatra. That mistake took a few comb-throughs to find. But after everything was set up, it was relatively smooth sailing. I would build a route, then it’s view, and then routes related to that view, and then the views related to those routes and so on. Then, after I had everything working, I added checks to make sure that data was only being edited by the creater. Finally, I refactored my code and formatted my HTML to look better.

Thanks for reading.

If you’re interested in seeing my app, click HERE.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store