Hidden Away: Behind the Rails Magic

Andrew Smoker
2 min readJan 22, 2021

--

The 3rd project is underway for my Flatiron Software Engineering cohort. This time around I am using the Rails “magic” to create an app that contains much more complicated relationships than I’ve ever done before. I stuck with something I am interested in and decided to expand my RACETRACKER app to include social interactions.

The complicated nature of my database (including three join tables) made it very difficult to set up the basic flow of the app. There was a moment while setting up my nested routes that I thought I wouldn’t come back from. I had lost track of where my routes were going and didn’t know how to change the setup! Bah! Rail does a lot for you behind the scenes and it’s easy to look past how everything is actually connecting. After many hours of studying and researching nested routes I finally got them functioning properly though!

Now I wanted to add a social element where a user could “like” another user’s data. It seemed easy at first and I got it functioning on one of my pages. But when I went to implement the same logic on a different page, the flow broke. I was stuck on how I could have a link_to handle the same method, but end up on different pages based on where the request had come from. After reading the Rails documents, I realized you could add a hidden field to a link_to!

My original link_to looked like this:

The problem was, I needed a way to determine it had come from the dashboard, so I could redirect back to the dashboard from my controller method. With the link_to option, you can add a hidden field and call it anything you would like. So I changed my link to the following:

It was as simple as adding dashboard: “yes” to my code. Then in my controller, I could check the params for [:dashboard] which told me to redirect back to the dashboard page! It was a small victory, but I never realized the option or purpose of adding a hidden field. Now I do and my users can “like” to their hearts content. I think that is part of becoming a programmer: you’re constantly learning ways to manipulate what’s going on under the hood.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Andrew Smoker
Andrew Smoker

Written by Andrew Smoker

I am 34 years old and making a huge career change by attending Flatiron School’s Software Engineering Bootcamp. Excited to learn!

No responses yet

Write a response