mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Make it simpler to make the root route an alias for another route. Closes #10818 [bscofield]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8738 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
*SVN*
|
||||
|
||||
* Make map.root accept a single symbol as an argument to declare an alias. #10818 [bscofield]
|
||||
|
||||
e.g. map.dashboard '/dashboard', :controller=>'dashboard'
|
||||
map.root :dashboard
|
||||
|
||||
* Handle corner case with image_tag when passed 'messed up' image names. #9018 [duncanbeevers, mpalmer]
|
||||
|
||||
* Add label_tag helper for generating elements. #10802 [DefV]
|
||||
|
||||
@@ -115,6 +115,12 @@ module ActionController
|
||||
# root_url # => 'http://www.example.com/'
|
||||
# root_path # => ''
|
||||
#
|
||||
# You can also specify an already-defined named route in your map.root call:
|
||||
#
|
||||
# # In routes.rb
|
||||
# map.new_session :controller => 'sessions', :action => 'new'
|
||||
# map.root :new_session
|
||||
#
|
||||
# Note: when using +with_options+, the route is simply named after the
|
||||
# method you call on the block parameter rather than map.
|
||||
#
|
||||
|
||||
@@ -19,6 +19,11 @@ module ActionController
|
||||
|
||||
# Creates a named route called "root" for matching the root level request.
|
||||
def root(options = {})
|
||||
if options.is_a?(Symbol)
|
||||
if source_route = @set.named_routes.routes[options]
|
||||
options = source_route.defaults.merge({ :conditions => source_route.conditions })
|
||||
end
|
||||
end
|
||||
named_route("root", '', options)
|
||||
end
|
||||
|
||||
|
||||
@@ -1808,6 +1808,30 @@ class RouteSetTest < Test::Unit::TestCase
|
||||
Object.send(:remove_const, :PeopleController)
|
||||
end
|
||||
|
||||
def test_recognize_with_alias_in_conditions
|
||||
Object.const_set(:PeopleController, Class.new)
|
||||
|
||||
set.draw do |map|
|
||||
map.people "/people", :controller => 'people', :action => "index",
|
||||
:conditions => { :method => :get }
|
||||
map.root :people
|
||||
end
|
||||
|
||||
request.path = "/people"
|
||||
request.method = :get
|
||||
assert_nothing_raised { set.recognize(request) }
|
||||
assert_equal("people", request.path_parameters[:controller])
|
||||
assert_equal("index", request.path_parameters[:action])
|
||||
|
||||
request.path = "/"
|
||||
request.method = :get
|
||||
assert_nothing_raised { set.recognize(request) }
|
||||
assert_equal("people", request.path_parameters[:controller])
|
||||
assert_equal("index", request.path_parameters[:action])
|
||||
ensure
|
||||
Object.send(:remove_const, :PeopleController)
|
||||
end
|
||||
|
||||
def test_typo_recognition
|
||||
Object.const_set(:ArticlesController, Class.new)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user