Skip to content

Commit 142d137

Browse files
committed
Add hyphenated/CamelCase controller name in routes to: pattern
Rails 4 validates controller names in `to:` clauses with strict rules: no hyphens, no CamelCase. Hyphenated values raise ArgumentError: 'foo-bar' is not a supported controller name; the CamelCase form raises the same error. Rails 3.2 was lenient and auto-normalized. Common shapes that trigger the regex: get "/", to: "my-pages#show" # hyphen get "/", to: "MyPages#show" # CamelCase URL paths (the route path itself) can keep hyphens — only the controller class reference in `to:` needs to be snake_case. The fix field calls this out so operators don't accidentally rewrite path strings. The snake_case form resolves to the same controller class on Rails 3.2, so the rewrite ships pre-bump and is backwards-compatible. Classified high_priority / kind: breaking — Rails 4 boot raises on the bad name.
1 parent bb7c1c5 commit 142d137

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

rails-upgrade/detection-scripts/patterns/rails-40-patterns.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ upgrade_findings:
182182
fix: "Keep the FIRST `root` declaration as the default `:root` name; add `as: :<unique_name>` to the SECOND and subsequent declarations. Renaming all of them (giving the first an `as:` too) silently breaks every `root_path` / `root_url` call site because the `:root` name is no longer registered. Real apps have dozens to hundreds of these helper calls. Verification step: `grep -rnE \"\\b(root_path|root_url)\\b\" app/ config/ lib/` and confirm no caller targets a constraint-bound root that was renamed"
183183
variable_name: "DUPLICATE_ROOT_ROUTES"
184184

185+
- name: "Hyphenated or CamelCase controller name in routes to: value"
186+
kind: "breaking"
187+
pattern: "to:\\s*\"[^\"]*(-|[A-Z])[^\"]*#"
188+
exclude: ""
189+
search_paths:
190+
- "config/"
191+
explanation: "Rails 4 validates controller names in `to:` clauses with strict rules: no hyphens, no CamelCase. Hyphenated values raise `ArgumentError: 'foo-bar' is not a supported controller name`; the CamelCase form raises the same error. Rails 3.2 was lenient. URL paths (the route path itself) can keep hyphens — only the controller class reference in `to:` needs to be snake_case"
192+
fix: "Replace hyphens with underscores and CamelCase with snake_case in `to:` values. URL paths keep their original form. The snake_case form resolves to the same controller class on Rails 3.2, so the rewrite ships pre-bump and is backwards-compatible. Example: `to: \"my-pages#show\"` → `to: \"my_pages#show\"`; `to: \"MyPages#show\"` → `to: \"my_pages#show\"`"
193+
variable_name: "ROUTES_CONTROLLER_NAMES"
194+
185195
medium_priority:
186196
- name: "rescue_action method"
187197
kind: "breaking"

0 commit comments

Comments
 (0)