Lately when I'm supposed to be getting actually useful things done, I find myself procrastinating by writing code instead. I have a Rails 6 codebase I've been fiddling with.
The other day as I did some reload-driven-development, I got this error:
Wow, development-mode error screens have come a long way since Rails 1. There's so much information here!
First off, there's the exception, the full path, and the message.
Then a nice source code listing with the error highlighted.
Followed by a trace with selectable app and framework filters.
Then there's a bunch more essential contextual info.
Then we get to the real doozy: an interactive REPL embedded right in the error page.
Ruby's auto-suggestion is great, until it's not. Here, the suggestion of the mysterious
video_path is worse than useless. There is no “video” concept in the application, so what even is this referring to? Presumably, somewhere in the thousands of methods known to the entire Ruby VM, it found a method called
video_path. This is going to be a “wait, what!?” moment for anyone who doesn't understand just how broad the auto-suggest feature can be.
But why is it even looking for a
votes_path method? Well, here we get to the actual problem, which is that
It was only the fact that I have a fair amount of experience with Rails form helpers that led me to realize that the fact it was looking for
votes_path instead of
canvass_votes_path, despite the nested resource array given to
model:, indicated that maybe
.canvass was missing. I have no idea how a Rails newbie would have figured this out. The fact that
form_with happily breezes by a
nil in the supplied array without so much as a warning is… unexpected.
It does not help in diagnosing the problem, that the apparent receiver for the incorrect route helper method is an inscrutable collection of symbols and hex. This is why, when I do metaprogramming that involves on-the-fly class or module generation, I like to generate a helpful name for the new class/module while I'm at it. I'm tempted to see if I can find where this class is being generated and submit a PR. At least in dev mode, it would be nice to have a meaningful generated moniker.