aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2013-03-24 12:55:43 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2013-03-24 12:55:43 -0700
commit822dd1340d5f794d7b8f94733f6693125f282e8d (patch)
tree78af9399cc1150af04bd448b6073fd4cf1ec78ea /actionpack/lib/action_dispatch
parent2cc3648f86435550185a48e125d56e125911c1f3 (diff)
parent1a25ebf884206df34b30a0bac8345d75fbc6d13c (diff)
downloadrails-822dd1340d5f794d7b8f94733f6693125f282e8d.tar.gz
rails-822dd1340d5f794d7b8f94733f6693125f282e8d.tar.bz2
rails-822dd1340d5f794d7b8f94733f6693125f282e8d.zip
Merge pull request #9704 from trevorturk/warn-about-skipped-routes
Raise an ArgumentError when a clashing named route is defined
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 619dd22ec1..7fb4719fa0 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -403,11 +403,19 @@ module ActionDispatch
def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
+ if name && named_routes[name]
+ raise ArgumentError, "Invalid route name, already in use: '#{name}' \n" \
+ "You may have defined two routes with the same name using the `:as` option, or "
+ "you may be overriding a route already defined by a resource with the same naming. " \
+ "For the latter, you can restrict the routes created with `resources` as explained here: \n" \
+ "http://guides.rubyonrails.org/routing.html#restricting-the-routes-created"
+ end
+
path = build_path(conditions.delete(:path_info), requirements, SEPARATORS, anchor)
conditions = build_conditions(conditions, path.names.map { |x| x.to_sym })
route = @set.add_route(app, path, conditions, defaults, name)
- named_routes[name] = route if name && !named_routes[name]
+ named_routes[name] = route if name
route
end