For Halloween this year, I’m releasing a new Ruby gem to banish the evil that haunts `config/routes.rb` on large Rails projects! 🎃👻
Bullet Train Routes adds a `model` method to the Rails routing DSL, a namespace-friendly alternative to `resources`.
Conversation
Replying to
Routing configuration can get very complicated when you introduce namespaces to keep your domain model organized. A few years ago I wrote a comprehensive guide for how to configure routes in any situation you could get yourself into.
1
4
But even with a complete guide (and Super Scaffolding generating routes for you!) there was no helping that the resulting `config/routes.rb` files were still very hard for any newcomer to parse and understand. We could get the URLs and path helpers we wanted, but... 😱
1
2
After years of just dealing with this in the name of keeping Bullet Train as "Rails-native" as possible, last week I had a spark of inspiration for how I might be able to solve this problem much better. Then I saw this tweet from :
Quote Tweet
Replying to @janklimo @LumSmith and @excid3
Automatic routing by default would be sick. So much can be inferred from controllers and folders. It’s *rare* that I’m in route.rb doing something complex.
1
2
My goal was different, but it convinced me that it was at least worth trying to see whether my idea had legs and could simplify routing, and whether I would even be able to implement it. Turns out, it only took a few hours and required around 100 lines of (very gnarly) code.
1
2
In the end, this dubious black magic eliminates the need for that entire blog post. Instead of all that craziness, we can now just write:
```
model "Project" do
model "Projects::Deliverable"
end
```
And the library does everything in the blog post automatically.
1
2
Most importantly, because `model` is just syntactic sugar on top of traditional Rails routing, we don't lose anything from the native Rails routing DSL. Everything you're used to is still available to you:
1
4
Finally, Bullet Train Routes doesn't depend on any other Bullet Train library, so you should be able to use it in any Rails project! I hope you find it useful!
5

