Module 2 Sinatra Project for Flatiron School
peabody00
Posted on March 8, 2021
Sinatra Project
This module has been a much different experience than the last one. In this module there were so many more concepts that we learned that I felt much more uncertain of what I was learning. The project has helped deepen my understanding of the concepts but I still feel like I am just barely scratching the surface. Luckily I have a few individuals that I rely on for support both technical and emotional (Thanks Evelyn and Jenny).
Here is a link to my project.
Project Idea
I struggled a lot more this time with my project idea. It changed a few times as I thought more about what was required of me and what I thought I could accomplish.
I finally settled on creating a simple trading card game. The basic idea is to collect cards to increase your Life score compared to other players. The interface allows a player to view their collection and open new card packs. There is a messaging area where players can post messages on a wall for all to see. A player can always edit and delete their own posts. There was a planned trading card feature that requires more work that I will talk about later.
Important Lessons
I learned many concepts while making this project but the biggest lesson came from ActiveRecord associations. I used some of the simpler associations during the course but learned about many other ways that ActiveRecord can associate models. My project uses 5 models User
, Card
, Post
, UserCard
, and Trade
.
Some associations were simple. A user has many posts, a post belongs to a user. Others got more complicated, a user has many cards and cards have many users. A usercard model was needed to join the other models so a usercard belongs to both users and cards.
As I thought through the unfinished trading feature the association became more complicated and unfamiliar. The way I tried to implement it was suggested by a coding partner. It involved using an alias and a foreign key to help identify both users and both cards in a trade.
class Card < ActiveRecord::Base
has_many :user_cards
has_many :trades
has_many :trades, :foreign_key => "other_card_id"
has_many :users, through: :user_cards
end
class Trade < ActiveRecord::Base
belongs_to :user
belongs_to :other_user, :class_name => "User"
belongs_to :card
belongs_to :other_card, :class_name => "Card"
end
However the more I thought about it that didn't seem to be the right relationship. It occurred to be that a users collection of cards existed in the usercards
table of the database. If that is the case then a trade needed a belongs to, through relationship. That doesn't seem supported in Sinatra as I researched it. There is a has one relationship that I need to research more but time was running out for my project.
I ended up making sure the features I had in program met all the requirements so I could turn that in. My plan is to work more on a trade feature before my project review.
Final Thoughts
I understand how things are building as I progress through my Flatiron Software Engineering course. Sometimes it is hard as we learn the fundamentals knowing that later tools will make doing what we are doing now easier. For now I will do my best to learn the material and enjoy the ride.
Posted on March 8, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.