Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Route root helper shortcut #5266

merged 1 commit into from

3 participants


Allow the root route helper to accept just a string

@bcardarella bcardarella Route root helper shortcut
Allow the root route helper to accept just a string

Nice shortcut. Actually I used it that way a few times only to realize that it's not a valid syntax.

@drogus drogus merged commit e09fd97 into rails:master
@drogus drogus merged commit 2ee4dd8 into rails:master

Yeah I figure this would be a minor shortcut as the :to is always implied. Thank-you for the merge.


@bcardarella I've documented this here. It would be great if the PRs include documentation too. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2012
  1. @bcardarella

    Route root helper shortcut

    bcardarella authored
    Allow the root route helper to accept just a string
This page is out of date. Refresh to see the latest.
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)
9 actionpack/test/controller/routing_test.rb
@@ -437,6 +437,15 @@ def test_named_route_root
assert_equal("/", routes.send(:root_path))
+ def test_named_route_root_without_hash
+ rs.draw do
+ root "hello#index"
+ end
+ routes = setup_for_named_route
+ assert_equal("", 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',
Something went wrong with that request. Please try again.