Animal Crossing Wish List — A Sinatra Application

Bhavani
4 min readApr 30, 2021

If you live in the united states, you might remember that the early months of the COVID-19 pandemic were marked by a sudden upsurge in the popularity of the game “animal crossing”. My friends and I are huge fans of the game, and we loved that we were able to stay connected even when we were in lockdown. The “New Horizons” version of the game consists of the player being in charge of developing an island, picking out villagers, clothing, and various items to decorate the island. My friends and I had a giant note on our phone’s notes app that we used to jot down items that we wanted, and items that we had excess of. As you can imagine, it was very hard to sort through. I decided to make a Sinatra application where users can log in and make a wish list for their dream villagers. I hope to continue to build this out to include other features that might make our lives easier.

Getting started

I used the corneal gem to create a basic app structure. This is a gem that was created by a former flatiron student to set up a Sinatra MVC application by simply running Gem install corneal in your terminal. Then run corneal new “insert name of your project here”, and voila! You have all the files needed to build your application

The dreaded MVC

The MVC structure can be daunting, I found the easiest way to tackle this was to start by creating the basic structure for my models and controllers, create your tables, seed some data to play with, and then switch back and forth between working on my controllers and views.

- Models: this holds your relationships between models, as well as any validations you decide to add. For my project I created a user and villager class that both inherit from ActiveRecord::Base. A user has_many villagers, and a villager belongs_to a user. I included validations to create error messages as well as prevent bad data entry and ensure uniqueness from users.

Here is an example of my User model:

- Seed data: After creating your table structures, I found that creating a seed file in your db folder is an easy way to make multiple users and associated data to ensure that everything is displaying correctly. I used the faker gem to create made up data to work with. I always add a puts message at the end to show that my data was seeded successfully in the terminal. A fun feature is to add an options hash and use the .sample method to get a random selection from that hash.

- Controllers: I found this was easiest to tackle next. The controllers are the go-between for models and views. It takes data from the browser to the application, and vice versa. My project has a top level application controller, which my sessions controller, users controller, and villagers controller all inherit from, while the application controller inherits from Sinatra::Base. I created a sessions controller to separate login/logout concerns. My signup controller was responsible for signing the user up and creating a new user. My villagers controller was the most difficult to create. It has CRUD functionality that allows the corresponding views pages to work.

Here is my users controller:

Views: this is the ‘front-end’ part of the application that contains things like HTML, CSS, and Javascript. Views are written in erb files. ERB is basically a templating engine that lets us change the structure of our HTML code to include ruby, with what I like to lovingly call “squid” (<%=) (the substitution tag) and “ice cream cone” (<%) the scripting tag.

This is an example of my users show page:

I really enjoyed building out this project and learned so much from it!

--

--