diff options
author | Trevor Turk <trevorturk@gmail.com> | 2013-03-19 23:23:55 -0500 |
---|---|---|
committer | Trevor Turk <trevorturk@gmail.com> | 2013-03-19 23:23:55 -0500 |
commit | a2b7c0e69d671294067b625c749be6fdbec7b433 (patch) | |
tree | b3a34425e1d6b7c84f317f025c858d7d752f03d7 /actionpack/lib/action_dispatch | |
parent | e61cdf02896ffe0a97cc2205a1a812d54638e19a (diff) | |
download | rails-a2b7c0e69d671294067b625c749be6fdbec7b433.tar.gz rails-a2b7c0e69d671294067b625c749be6fdbec7b433.tar.bz2 rails-a2b7c0e69d671294067b625c749be6fdbec7b433.zip |
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.rb | 9 |
1 files changed, 8 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..38e9288572 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -403,11 +403,18 @@ 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" \ + "This conflict might arise if your routes contain `resources :#{name.pluralize}`. " \ + "If so, 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 |