diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-07-17 19:15:10 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-07-17 20:09:28 +0100 |
commit | 71d274dbbb3972afb7808a84ecdd005d95107212 (patch) | |
tree | 2461f8366e920df80b76ac61bb483bd6edc8315a /actionpack/lib | |
parent | e23ec4c79c7f402f3d306771616c1d597132e2fa (diff) | |
download | rails-71d274dbbb3972afb7808a84ecdd005d95107212.tar.gz rails-71d274dbbb3972afb7808a84ecdd005d95107212.tar.bz2 rails-71d274dbbb3972afb7808a84ecdd005d95107212.zip |
Add support for optional root segments containing slashes
Optional segments with a root scope need to have the leading slash
outside of the parentheses, otherwise the generated url will be empty.
However if the route has non-optional elements then the leading slash
needs to remain inside the parentheses otherwise the generated url
will have two leading slashes, e.g:
Blog::Application.routes.draw do
get '/(:category)', :to => 'posts#index', :as => :root
get '/(:category)/author/:name', :to => 'posts#author', :as => :author
end
$ rake routes
root GET /(:category)(.:format) posts#index
author GET (/:category)/author/:name(.:format) posts#author
This change adds support for optional segments that contain a slash,
allowing support for urls like /page/2 for the root path, e.g:
Blog::Application.routes.draw do
get '/(page/:page)', :to => 'posts#index', :as => :root
end
$ rake routes
root GET /(page/:page)(.:format) posts#index
Fixes #7073
(cherry picked from commit d8745decaf59aad32aa2f09abdba99b8d0e48b31)
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 82062c0cd5..40ff69693b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -238,7 +238,7 @@ module ActionDispatch # for root cases, where the latter is the correct one. def self.normalize_path(path) path = Journey::Router::Utils.normalize_path(path) - path.gsub!(%r{/(\(+)/?}, '\1/') unless path =~ %r{^/\(+[^/]+\)$} + path.gsub!(%r{/(\(+)/?}, '\1/') unless path =~ %r{^/\(+[^)]+\)$} path end |