Ticket #10818: add_alias_key_to_route_options.patch
| File add_alias_key_to_route_options.patch, 3.2 kB (added by bscofield, 6 months ago) |
|---|
-
actionpack/test/controller/routing_test.rb
old new 1781 1781 Object.send(:remove_const, :PeopleController) 1782 1782 end 1783 1783 1784 def test_recognize_with_alias_in_conditions 1785 Object.const_set(:PeopleController, Class.new) 1786 1787 set.draw do |map| 1788 map.people "/people", :controller => 'people', :action => "index", :conditions => { :method => :get } 1789 map.persons '/persons', :alias => :people 1790 map.root :alias => :people 1791 end 1792 1793 request.path = "/people" 1794 request.method = :get 1795 assert_nothing_raised { set.recognize(request) } 1796 assert_equal("people", request.path_parameters[:controller]) 1797 assert_equal("index", request.path_parameters[:action]) 1798 1799 request.path = "/persons" 1800 request.method = :get 1801 assert_nothing_raised { set.recognize(request) } 1802 assert_equal("people", request.path_parameters[:controller]) 1803 assert_equal("index", request.path_parameters[:action]) 1804 1805 request.path = "/" 1806 request.method = :get 1807 assert_nothing_raised { set.recognize(request) } 1808 assert_equal("people", request.path_parameters[:controller]) 1809 assert_equal("index", request.path_parameters[:action]) 1810 ensure 1811 Object.send(:remove_const, :PeopleController) 1812 end 1813 1784 1814 def test_typo_recognition 1785 1815 Object.const_set(:ArticlesController, Class.new) 1786 1816 -
actionpack/lib/action_controller/routing.rb
old new 168 168 # # provides named routes for show, delete, and edit 169 169 # link_to @article.title, show_path(:id => @article.id) 170 170 # 171 # == Route aliasing 172 # 173 # You can use the <tt>:alias</tt> key to reuse a given set of parameters 174 # for multiple named routes, as well as for the route URL. 175 # 176 # Example: 177 # # In routes.rb 178 # map.new_session 'sessions/new', :controller => 'sessions', :action => 'new' 179 # map.login 'login', :alias => :login 180 # 181 # # would recognize both /sessions/new and /login as 182 # params = { :controller => 'sessions', :action => 'index' } 183 # 184 # You can also use the <tt>:alias</tt> key with map.root 185 # 186 # # In routes.rb 187 # map.new_session 'sessions/new', :controller => 'sessions', :action => 'new' 188 # map.root :alias => :new_session 189 # 171 190 # == Pretty URLs 172 191 # 173 192 # Routes can generate pretty URLs. For example: … … 1304 1323 end 1305 1324 1306 1325 def add_named_route(name, path, options = {}) 1326 if source_route_name = options.delete(:alias) 1327 if source_route = named_routes.routes[source_route_name] 1328 options = source_route.defaults.merge({ :conditions => source_route.conditions }) 1329 end 1330 end 1331 1307 1332 # TODO - is options EVER used? 1308 1333 name = options[:name_prefix] + name.to_s if options[:name_prefix] 1309 1334 named_routes[name.to_sym] = add_route(path, options)