Second Time Around -Flatiron Ruby Code Challenge
Tags: flatironschool, ruby, rails, beginners
Published: 2023-01-05 14:52:11

         "The second time around
          I know you come a long way, Baby
          But you don’t need that heart of stone, no
          You proved that you could do it, do it, Baby,
          You could make it on your own” -Shalalmar
 
 
“You can make it on your own”……not quite . Cold challenge week is always the most stressful week at Flatiron School.  However, my issues started in week two, Phase 3 Thanksgiving week, …somewhere in Jamaica.   We had daily power outages which of course affected the internet, and this just hindered me tremendously.   I was way behind on everything, lectures, classwork and BLOGS of course.   I knew it would be nearly impossible to pass the code challenge the following week.   These outages and connectivity issues continued into code challenge week, and I could not focus on anything.   The back end looked so daunting.  I was inside pry thinking how much I couldn’t even understand what I was reading and how much I missed React, the lights, the colors, the action.  I had to find a way to push through and there was no way I could make it on my own.   I needed help Bigtime!  
 
I first sought help for my mental by getting a chakra balancing/tapping session from my friend, @ramibesjoni.  That kid has a gift!  I opened my laptop right after my session and what do you know - I suddenly could understand what I was reading.   It’s amazing what a little energy work can do.   That night I started tackling some of the code challenge review videos and it was a long 4-hour video by one of my cohort teachers, Sam Boehen, that solidified my basic understanding of Ruby. Would it be enough to pass the code challenge?  I went over that video 3 times total and counting!  That is 12hours on one video and even longer actually, because I coded along.
 
The night before Phase-3 coding challenge I fell asleep on my laptop at about 10pm, and just as I knew, I did not pass the code challenge.  If you were expecting this to be a story of triumph, well …it’s not.  It a story of failure and acceptance but most importantly, PERSEVERANCE. The first time I failed a code challenge I bawled my eyes out. When the 90 minutes were up, I immediately closed my laptop and the crying commenced. I was bummed for days! That was in a previous cohort and after I failed, I took a leave of absence, unsure if I would ever attempt Data Engineer Bootcamp again. But here I am “The second time around” and I quote because this song was playing in my head the day after I failed Phase 3 code challenge. I know not from whence this song came but I had to google the song to listen to it and read the lyrics.  
 
This disco beat rang PESEVERANCE ----that this time I did not bend nor break nor cry.   I FAILED…but when the clock struck 90 mins, and long after I had submitted Amira.bundle, I kept working.   BigUP to Mathew Lui who took time out to help me through some of the areas I was stuck on. Massive Big Up to Sam Boehen, if it wasn’t for your mSM dance I could not have gotten as far as I did in the code challenge. 
 
 
What exactly is mSM? 
                    
                     msM = migrate, Seed, Model

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yh71grrtf9awuwwt2ms0.jpg)

mSM is a dance of sort in Ruby, a check and balance, to ensure we have all the fundamentals of Ruby in place before writing class and instance methods. Our migrations gives us the table. Then we create our Models. Models describes how every instance of that class should behave so when we go to our seed file we are making instances .  Those instances, when we run rake db:seed,  the data gets seeded and populated into the database .  This is a high- level reason for the order, the dance. You can create any one of the steps first however, if you created and ran your seed file, where is the information going if you don’t have a migration(s) table?  If you are making seeds, how do you make instances if you don’t have a model? This is the reason for the order of the mSM dance!  It is the most optimal and efficient workflow to ensure you are not trying to do one thing that depends on another that doesn’t exist.   

1.   Migration to Model
 
"Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent.
You can think of each migration as being a new 'version' of the database. A schema starts off with nothing in it, and each migration modifies it to add or remove tables, columns, or entries. Active Record knows how to update your schema along this timeline, bringing it from whatever point it is in the history to the latest version. Active Record will also update your db/schema.rb file to match the up-to-date structure of your database"


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rljoa0myiw37rii31kli.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chbkeascsxwgg5zb80d0.png)

2.  Model to Seed 
 
Create your .rb models with singular,  lowercase names corresponding to the plural version of your migrations files, add your associations and foreign keys to your join table 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x646fa4twyyl2cl1quel.png)

3.  Seed to Methods
 
Create your seeds!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iuj6k9cssgeokmdtguyl.png)

4.  Seed to Model

Once you get back your models after seeding, it is time to test your macros in your .rb files before writing your instance and class methods.   Open rake console and check each of the associations in rake.  If you get correct answers, migration and seeding was done correctly. You can now move on to writing instance and class Methods.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bfi11cqd97yxn0t2ftc.png)

_If you get correct answers, migration and seeding was done correctly, you can move on to writing instance and class Methods inside your Models.
 _
 
Conclusion: If you are struggling to understand Ruby fundamentals and just the process of getting through a Ruby code challenge, I believe the mSM dance will help you organize your thoughts and processes before getting into the nitty gritty of writing your instance and class method and completing the ruby code challenge deliverables.More on writing instance and class methods later.   Read my next blog to find out if I passed the coding challenge retake as failing a second time at Flatiron means using my one and only phase repeat and/or dismissal if you repeated a phase already. Welcome to SE Bootcamp!  Happy Coding!!!!