Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add router DSL to explicitly match all verbs #9840

Closed
wants to merge 1 commit into from

4 participants

@trliner

This commit allows calling +match+ with a :via => :all option to explicitly match all verbs.

The :via => :all option was added to Rails 4 in the process of deprecating +match+ (#5964). To facilitate the migration to Rails 4, it would be helpful to make this option available in Rails 3.

@trliner trliner Add router DSL to explicitly match all verbs
This commit allows calling +match+ with a
:via => :all option to explicitly match all verbs.

The :via => :all option was added to Rails 4 in
the  process of deprecating +match+ (#5964). To
facilitate the migration to Rails 4, it would be
helpful to make this option available in Rails 3.
c419cff
@carlosantoniodasilva

I think I'd rather not have this option in Rails 3, so that people can consciously choose whether they're really needing a get/post VS allowing to match all. By adding this option, we'd opening the ports for everyone to change match to match all to solve the problem, and the overall idea of not allowing match with a specific verb/verbs would be kinda useless I think. Just my cents about the change, lets get other feedback before acting. Thanks for your contribution.

@neerajdotname
Collaborator

+1 to what @carlosantoniodasilva said .

@guilleiguaran

Sorry but we don't backport features from master to stable versions, 3.2.x is only receiving bug fixes.

Thanks for you contribution!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2013
  1. @trliner

    Add router DSL to explicitly match all verbs

    trliner authored
    This commit allows calling +match+ with a
    :via => :all option to explicitly match all verbs.
    
    The :via => :all option was added to Rails 4 in
    the  process of deprecating +match+ (#5964). To
    facilitate the migration to Rails 4, it would be
    helpful to make this option available in Rails 3.
This page is out of date. Refresh to see the latest.
View
3  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -198,7 +198,7 @@ def constraints
end
def request_method_condition
- if via = @options[:via]
+ if (via = @options[:via]) && (via != :all)
list = Array(via).map { |m| m.to_s.dasherize.upcase }
{ :request_method => list }
else
@@ -313,6 +313,7 @@ def root(options = {})
#
# match 'path' => 'c#a', :via => :get
# match 'path' => 'c#a', :via => [:get, :post]
+ # match 'path' => 'c#a', :via => :all
#
# [:to]
# Points to a +Rack+ endpoint. Can be an object that responds to
View
12 actionpack/test/controller/routing_test.rb
@@ -758,6 +758,18 @@ def test_recognize_array_of_methods
assert_equal 'not_get_or_post', params[:action]
end
+ def test_recognize_all_option
+ rs.draw do
+ match '/match' => 'books#all', :via => :all
+ end
+
+ params = rs.recognize_path("/match", :method => :get)
+ assert_equal 'all', params[:action]
+
+ params = rs.recognize_path("/match", :method => :post)
+ assert_equal 'all', params[:action]
+ end
+
def test_subpath_recognized
rs.draw do
match '/books/:id/edit' => 'subpath_books#edit'
Something went wrong with that request. Please try again.