Permalink
Browse files

Merge pull request #5266 from bcardarella/root_with_string_options

Route root helper shortcut
  • Loading branch information...
2 parents 44e7967 + 2ee4dd8 commit e09fd970183fe1d4f65f3bc7a68de4041042c0fd @drogus drogus committed Mar 4, 2012
Showing with 14 additions and 0 deletions.
  1. +5 −0 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +9 −0 actionpack/test/controller/routing_test.rb
View
5 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -254,10 +254,15 @@ module Base
#
# For options, see +match+, as +root+ uses it internally.
#
+ # You can also pass a string which will expand
+ #
+ # root 'pages#main'
+ #
# You should put the root route at the top of <tt>config/routes.rb</tt>,
# because this means it will be matched first. As this is the most popular route
# of most Rails applications, this is beneficial.
def root(options = {})
+ options = { :to => options } if options.is_a?(String)
match '/', { :as => :root }.merge(options)
end
View
9 actionpack/test/controller/routing_test.rb
@@ -437,6 +437,15 @@ def test_named_route_root
assert_equal("/", routes.send(:root_path))
end
+ def test_named_route_root_without_hash
+ rs.draw do
+ root "hello#index"
+ end
+ routes = setup_for_named_route
+ assert_equal("http://test.host/", routes.send(:root_url))
+ assert_equal("/", routes.send(:root_path))
+ end
+
def test_named_route_with_regexps
rs.draw do
match 'page/:year/:month/:day/:title' => 'page#show', :as => 'article',

0 comments on commit e09fd97

Please sign in to comment.