Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8738

Show
Ignore:
Timestamp:
01/26/08 08:41:19 (4 months ago)
Author:
nzkoz
Message:

Make it simpler to make the root route an alias for another route. Closes #10818 [bscofield]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r8717 r8738  
    11*SVN* 
     2 
     3* Make map.root accept a single symbol as an argument to declare an alias.  #10818 [bscofield]  
     4 
     5  e.g.  map.dashboard '/dashboard', :controller=>'dashboard' 
     6        map.root      :dashboard 
    27 
    38* Handle corner case with image_tag when passed 'messed up' image names. #9018 [duncanbeevers, mpalmer] 
  • trunk/actionpack/lib/action_controller/routing.rb

    r8674 r8738  
    116116  #   root_path  # => '' 
    117117  # 
     118  # You can also specify an already-defined named route in your map.root call: 
     119  # 
     120  #   # In routes.rb 
     121  #   map.new_session :controller => 'sessions', :action => 'new' 
     122  #   map.root :new_session 
     123  # 
    118124  # Note: when using +with_options+, the route is simply named after the 
    119125  # method you call on the block parameter rather than map. 
  • trunk/actionpack/lib/action_controller/routing/route_set.rb

    r8674 r8738  
    2020        # Creates a named route called "root" for matching the root level request. 
    2121        def root(options = {}) 
     22          if options.is_a?(Symbol) 
     23            if source_route = @set.named_routes.routes[options] 
     24              options = source_route.defaults.merge({ :conditions => source_route.conditions }) 
     25            end 
     26          end 
    2227          named_route("root", '', options) 
    2328        end 
  • trunk/actionpack/test/controller/routing_test.rb

    r8673 r8738  
    18091809  end 
    18101810   
     1811  def test_recognize_with_alias_in_conditions 
     1812    Object.const_set(:PeopleController, Class.new) 
     1813 
     1814    set.draw do |map| 
     1815      map.people "/people", :controller => 'people', :action => "index", 
     1816        :conditions => { :method => :get } 
     1817      map.root   :people 
     1818    end 
     1819 
     1820    request.path = "/people" 
     1821    request.method = :get 
     1822    assert_nothing_raised { set.recognize(request) } 
     1823    assert_equal("people", request.path_parameters[:controller]) 
     1824    assert_equal("index", request.path_parameters[:action]) 
     1825 
     1826    request.path = "/" 
     1827    request.method = :get 
     1828    assert_nothing_raised { set.recognize(request) } 
     1829    assert_equal("people", request.path_parameters[:controller]) 
     1830    assert_equal("index", request.path_parameters[:action]) 
     1831  ensure 
     1832    Object.send(:remove_const, :PeopleController) 
     1833  end 
     1834 
    18111835  def test_typo_recognition 
    18121836    Object.const_set(:ArticlesController, Class.new)