Commit bb7c1c5
committed
Add duplicate root route declarations pattern
Rails 4 raises ArgumentError: Invalid route name, already in use:
'root' when the routes file has more than one `root` declaration
(typically one per constraint block). Rails 3.2 was lenient about
duplicate names with different constraints, so this slips through on
many 3.x codebases.
The naive fix — give each duplicate an `as:` — silently breaks every
root_path / root_url caller in the codebase because the :root name
is no longer registered to any declaration. Real apps have dozens to
hundreds of these helper calls in controllers, views, mailers, and
tests.
Correct fix: keep the FIRST declaration as the default :root, only
add `as:` to the SECOND and subsequent. Includes a grep verification
step so operators confirm no caller targets a constraint-bound root
that was renamed.
Classified high_priority / kind: breaking — Rails 4 boot raises
outright on the duplicate.1 parent de9009c commit bb7c1c5
1 file changed
Lines changed: 10 additions & 0 deletions
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
175 | 185 | | |
176 | 186 | | |
177 | 187 | | |
| |||
0 commit comments