Surprising journey of a typo and a label method

Petr Zaparka
3 min readNov 27, 2019

When something that looks like a typo, turns into a dive into an ActionView.

I’m currently migrating our old Rails to newer version. This upgrade includes adding latest Frontend library which includes all css, js, fonts, images you name it.

After doing all the basic work our tester point out a typo in the label on a radio button.

When I saw it, I thought to myself that I didn’t change anything in the translation file. And I was right.

After seeing the translation file is correct, I copy and paste the translation method only on a separate line.

Then I thought something is fishy here I removed all the CSS from the elements, but it was still same.

Time to dig deeper

I put a debugger in, right before the label.

I also changed the translation to ABCDEFGH, to see that the right translation is used (one never knows).

So right translation is used but the method is changing the label text for some reason. Time to look at the

ActionView::Helpers::FormBuilder that we are using.

As you can see FormBuilder is in actionview gem to open it for debugging.

I use:

bundle open actionview

which opens the gem in my Sublime editor

I find the label method

Which then took me to this method

and then finally the translation method, where I put my debugger again.

I inspected a few values from the method and saw this:

Finally. So I know what is happening now. But why???

And then I looked at the method again and thought “Why is the method_name having a title for the label?

AHH I SEE.

There is a method name missing!

After adding the method name it looks as it should.

I hope that you enjoyed my little dig into what’s behind the label method. And next time something like this happens to you, don’t forget, a debugger is your friend.

PS: I know that I could look at the definition of the method first, but to be honest, it didn’t cross my mind since the label was working except the text was not formatted well. What can I say, lesson learned :).

--

--

Petr Zaparka

I love wine, self-improvement, chocolate and running. I do web development for a living. You can visit zaparka.cz or drop me an email petr@zaparka.cz