Rails Gets Spooky Part 2

Riley Redfern
3 min readJan 28, 2021

One could argue that the scariest part of learning to code is getting accustomed to doing it while someone else is watching. Sitting alone with music gently playing in the background while you poke around the internet and watch tutorials is one thing but you really don’t know what you don’t know until you’re on the spot. I’d like to make two things clear to any other bootcamp students out there: 1- You will be surprised to learn how much your brain is capable of retaining and 2- You should never underestimate the power of well-laid plan.

As part of my rails project assessment, I was asked to implement a search function in live code. My first instinct was to think, “I have no idea how to do that. I’m hosed.” but with some gentle prodding from my assessor was reminded to break the steps of implementation down into smaller pieces first. This, I could do.

In order to give the user the ability to search for a specific story and get the correct result I guessed I needed to do 4 things :

Give the user a place to enter their search criteria.

Make sure that information goes to the right place in the database so it can be compared against existing data.

Give the application some logic to follow ie: If the name of the scary story searched for matches the name of an existing record*closely enough*, go ahead and send that back to the user.

And finally a rendering of the data requested.

Beginning in the index view of my program I built a form_tag form to *get* data from my index action, which is the action already responsible for retrieving every story in my database. This was all that was necessary, aside from minor page formatting, to change from the user's perspective.

From here, in my stories controller, I plugged into my index action some logic to determine IF the story searched for exists with a little wiggle room for error, assign that nugget of information to a variable that my view is already formatted to handle so it can present it to the user.

A more experienced programmer wouldn’t need to be reminded to maybe move the database manipulation pieces of code to the model.rb file because after all, that’s where database logic would always ideally be handled.

Once this was done I realized that while in the moment it took me the better part of 30 minutes with LOTS of hints to produce this functionality, the logic of this task was already present in my mind when I sat down to my assessment. By breaking the problem into smaller pieces it was much easier to take on and more surprisingly to me, I already KNEW the way there.

All this is really just to say, have confidence in your ability to learn, it’s hard to notice how fast it’s happening in real-time. And more importantly, practice live-coding as much as possible as the best defense against the scariest thing in the world which is freezing up completely in a Zoom call with your assessor 😳!

--

--