Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow named_routes to be used with root, and with new DSL short-form.

The real use case it to make all of the following act the same:

  root 'store#index', :as => 'store'
  match '/' => 'store#index', :as => 'store'
  match '/', :to => 'store#index', :as => 'store'

The test case provided deviates from this in order to demonstrate all three
forms in a single set of test routes.

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit aa3565f3a6327c947ded314525ba1d0674d5a71e 1 parent 84f1137
@rubys rubys authored jeremy committed
View
15 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -35,18 +35,17 @@ def initialize(set)
end
def root(options = {})
- raise "Can't rename root to #{options[:as].inspect}: root is always named 'root'" if options.include?(:as)
- match '/', options.merge(:as => :root)
+ match '/', options.reverse_merge(:as => :root)
end
def match(*args)
- if args.one? && args.first.is_a?(Hash)
- options = args.first
- path = options.keys.first
- options[:to] = options.delete(path)
+ options = args.extract_options!
+
+ if args.empty?
+ path, to = options.find {|name,value| name.is_a?(String)}
+ options.merge!(:to => to).delete(path) if path
else
- path = args.first
- options = args.extract_options!
+ path = args.first
end
conditions, defaults = {}, {}
View
9 actionpack/test/dispatch/routing_test.rb
@@ -111,6 +111,7 @@ def self.matches?(request)
end
root :to => 'projects#index'
+ match '/info' => 'projects#info', :as => 'info'
end
end
@@ -469,6 +470,14 @@ def test_root
end
end
+ def test_index
+ with_test_routes do
+ assert_equal '/info', info_path
+ get '/info'
+ assert_equal 'projects#info', @response.body
+ end
+ end
+
private
def with_test_routes
real_routes, temp_routes = ActionController::Routing::Routes, Routes
Please sign in to comment.
Something went wrong with that request. Please try again.