Commit 1a0aaa9
committed
Add top-level module in route file pattern
Rails 4's route loader does not reliably persist top-level module
definitions across the routes-reload boundary. A pattern like
module Constraints
class Admin
...
end
end
defined inside a config/routes/*.rb file may evaluate at boot but
the Constraints constant does not survive subsequent reloads, and
downstream uses like `constraints Constraints::Admin do ... end`
raise NameError: uninitialized constant Constraints. Rails 3.2
handled this more leniently — modules defined in route files
persisted across reload boundaries.
Fix is two-part, branched on NextRails.next?:
1. Move the module's class definitions to convention paths
(e.g. config/routes/constraints/admin.rb for Constraints::Admin)
so Rails autoload finds them.
2. Add the parent directory to config.autoload_paths, also gated by
NextRails.next?, so the new layout only applies on the Rails 4+
side. Rails 3.2 still wants the modules at the original path
inside the route file.
The exclude regex skips RSpec:: and Constraints:: references that
match the leading `module` pattern but are not actual module
definitions.
Classified high_priority / kind: breaking — Rails 4 raises NameError
on the first reload that hits the dropped constant.1 parent 142d137 commit 1a0aaa9
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 | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
195 | 205 | | |
196 | 206 | | |
197 | 207 | | |
| |||
0 commit comments