diff options
author | John Mileham <jmileham@gmail.com> | 2011-03-24 15:03:08 -0400 |
---|---|---|
committer | John Mileham <jmileham@gmail.com> | 2011-03-24 15:03:08 -0400 |
commit | b44a0ec153c84384e9b97a069e81f28bc5c2a4bf (patch) | |
tree | 94713aff0c241f91530dfd714bf685019c84ccab /actionpack/lib/action_dispatch/routing/mapper.rb | |
parent | d5994ee48af14d67f0eec7d23863d4b19211b078 (diff) | |
parent | 5214e73850916de3c9127d35a4ecee0424d364a3 (diff) | |
download | rails-b44a0ec153c84384e9b97a069e81f28bc5c2a4bf.tar.gz rails-b44a0ec153c84384e9b97a069e81f28bc5c2a4bf.tar.bz2 rails-b44a0ec153c84384e9b97a069e81f28bc5c2a4bf.zip |
Merge branch 'master' of github.com:rails/rails into count_behavior
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 589df218a8..14c424f24b 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -107,7 +107,7 @@ module ActionDispatch if @options[:format] == false @options.delete(:format) path - elsif path.include?(":format") + elsif path.include?(":format") || path.end_with?('/') || path.match(/^\/?\*/) path else "#{path}(.:format)" @@ -195,8 +195,8 @@ module ActionDispatch def request_method_condition if via = @options[:via] - via = Array(via).map { |m| m.to_s.dasherize.upcase } - { :request_method => %r[^#{via.join('|')}$] } + list = Array(via).map { |m| m.to_s.dasherize.upcase } + { :request_method => list } else { } end @@ -243,10 +243,6 @@ module ActionDispatch end module Base - def initialize(set) #:nodoc: - @set = set - end - # You can specify what Rails should route "/" to with the root method: # # root :to => 'pages#main' @@ -368,9 +364,17 @@ module ActionDispatch # match 'path' => 'c#a', :defaults => { :format => 'jpg' } # # See <tt>Scoping#defaults</tt> for its scope equivalent. + # + # [:anchor] + # Boolean to anchor a #match pattern. Default is true. When set to + # false, the pattern matches any request prefixed with the given path. + # + # # Matches any request starting with 'path' + # match 'path' => 'c#a', :anchor => false def match(path, options=nil) - mapping = Mapping.new(@set, @scope, path, options || {}).to_route - @set.add_route(*mapping) + mapping = Mapping.new(@set, @scope, path, options || {}) + app, conditions, requirements, defaults, as, anchor = mapping.to_route + @set.add_route(app, conditions, requirements, defaults, as, anchor) self end @@ -558,11 +562,6 @@ module ActionDispatch # PUT /admin/posts/1 # DELETE /admin/posts/1 module Scoping - def initialize(*args) #:nodoc: - @scope = {} - super - end - # Scopes a set of routes to the given default options. # # Take the following route definition as an example: @@ -700,7 +699,7 @@ module ActionDispatch # Now routes such as +/posts/1+ will no longer be valid, but +/posts/1.1+ will be. # The +id+ parameter must match the constraint passed in for this example. # - # You may use this to also resrict other parameters: + # You may use this to also restrict other parameters: # # resources :posts do # constraints(:post_id => /\d+\.\d+) do @@ -720,7 +719,7 @@ module ActionDispatch # # === Dynamic request matching # - # Requests to routes can be constrained based on specific critera: + # Requests to routes can be constrained based on specific criteria: # # constraints(lambda { |req| req.env["HTTP_USER_AGENT"] =~ /iPhone/ }) do # resources :iphones @@ -956,11 +955,6 @@ module ActionDispatch alias :nested_scope :path end - def initialize(*args) #:nodoc: - super - @scope[:path_names] = @set.resources_path_names - end - def resources_path_names(options) @scope[:path_names].merge!(options) end @@ -1473,6 +1467,11 @@ module ActionDispatch end end + def initialize(set) #:nodoc: + @set = set + @scope = { :path_names => @set.resources_path_names } + end + include Base include HttpHelpers include Redirection |