My Sinatra App — An Instrument Catalog

It’s that time again. I’ve reached the end of another section along my path through the Learn Verified program. For this assessment, I was tasked with creating a Sinatra app. I’ll now describe my process for this project.

Where to Start?

Creating an app from scratch left me initially overwhelmed, especially regarding creating the directory structure. I had a general idea of how it should look, but I knew there had to be a faster way instead of having to manually create each new file. As the Learn curriculum has repeatedly, and endearingly, said, “Coders are lazy!” We want things to be easy, quick, and minimal effort. So I did a little digging on Google and GitHub and found that another Learn student created a gem that mass-created the directory structure for a Sinatra app — perfect!

After some brainstorming, I decided that my app would catalog a user’s instrument collection. Being a musician myself, I thought it would be helpful to catalog instruments by name and description. Now, I personally don’t have a lot of instruments, but a guy can dream, can’t he?!

On to Coding!

My app would only require two models: User and Instrument. It would also need corresponding table, views, and controllers. I also wanted my app to be a little more stylized, so I went the Bootstrap route. When all was said and done, my directory structure was as follows:

├── config.ru
├── Gemfile
├── Gemfile.lock
├── LICENSE.txt
├── Rakefile
├── README.md
├── app
│ ├── controllers
│ │ └── application_controller.rb
│ │ └── instruments_controller.rb
│ │ └── users_controller.rb
│ ├── models
│ | ├── concerns
│ | | └── slugifiable.rb
│ | ├── instrument.rb
| │ ├── user.rb
│ └── views
│ | ├── instruments
│ | | └── edit.erb
│ | | └── insruments.erb
│ | | └── new.erb
│ | | └── show.erb
│ | ├── users
│ | | └── login.erb
│ | | └── show.erb
│ | | └── signup.erb
│ | ├── layout.erb
│ | ├── index.erb
├── config
│ | ├── initializers
│ | | └── environment.rb
├── db
│ | ├── migrate
│ | | └── *date_created*_create_users.rb
│ | | └── *date_created*_create_instruments.rb
│ | ├── development.sqlite
│ | ├── schema.rb
│ | | └── test.sqlite
├── lib
│ | └── .gitkeep
├── public
| | ├── css
│ | | └── bootstrap-theme.css
│ | | └── bootstrap-theme.css.map
│ | | └── bootstrap-theme.min.css
│ | | └── bootstrap-theme.min.css.map
│ | | └── bootstrap.css
│ | | └── bootstrap.css.map
│ | | └── bootstrap.min.css
│ | | └── bootstrap.min.css.map
| | ├── fonts
│ | | └── glyphicons-halflings-regular.eot
│ | | └── glyphicons-halflings-regular.svg
│ | | └── glyphicons-halflings-regular.ttf
│ | | └── glyphicons-halflings-regular.woff
│ | | └── glyphicons-halflings-regular.woff2
| | └── js
| | | └── bootstrap.js
| | | └── bootstrap.min.js
| | | └── npm.js
├── spec
| | ├── application_controller_spec.rb
| | | └── spec_helper.rb

As you can see, this directory structure assumes that you’ve already run rake db:create migration for both the User and Instrument tables.

From there I went to the bulk of the coding. Including Bootstrap was challenging, but not too bad once I noticed the patterns and such (e.g. div classes). Later on, I ran into problems getting the rack-flash gem to work. A little searching around and I found the sinatra-flash gem, which seemed to do the trick!

The process of creating the routes in the various controllers wasn’t too bad either. The previous labs in the Learn program did a great job preparing me for what to expect, so it was easy to tweak the routes to serve my Instrument app.

Final Thoughts

When I look back at this project, I’m proud of what I was able to produce. I still don’t think it has sunk in yet…I MADE AN APP!? Granted it’s pretty basic, but still…I MADE AN APP!

Like what you read? Give Michael Casciato a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.