Rails, autoloading, routes, and you

Published by Kyle Bragger

A few days back, while deploying a batch of new code to BricaBox’s production…er…boxes, we hit somewhat of a roadblock: Rails’ autoloader was killing a few of our namespaced routes (e.g. /block_builder/tags/some_action). Stranger yet, the issue seemed to only occur in production, not in any of our dev instances. After some thoughtful conversation with Lee at EngineYard, ensuring our monit config wasn’t acting up again, and investigating the more obvious possibilities, turns out it was in fact Rails’ own naming conventions for controller filenames that was causing the whole thing; one quick rename of a controller file and we were good to go. The route parser was hitting “block_builder”, finding a controller class to match (by way of the autoloader), incorrectly setting our action to “tags”, and proceeding from there. By renaming block_builder_controller.rb to something else, it was essentially hidden from the autoloader, thus allowing Routing to correctly parse “block_builder/tags” as a namespaced controller, passing back “some_action” as our action, etc.

The moral of the story? If shit starts acting up, check your filenames!

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image