Ticket #8558: deprecated_resource_routing.diff
| File deprecated_resource_routing.diff, 33.6 kB (added by pixeltrix, 2 years ago) |
|---|
-
actionpack/test/controller/resources_test.rb
old new 10 10 class MessagesController < ResourcesController; end 11 11 class CommentsController < ResourcesController; end 12 12 13 class AccountController < ResourcesController; end 14 class AdminController < ResourcesController; end 13 class AccountController < ResourcesController; end 14 class AdminController < ResourcesController; end 15 class ProductsController < ResourcesController; end 15 16 16 17 class ResourcesTest < Test::Unit::TestCase 17 18 def test_should_arrange_actions … … 63 64 end 64 65 end 65 66 66 def test_multi le_with_path_prefix67 def test_multiple_with_path_prefix 67 68 with_restful_routing :messages, :comments, :path_prefix => '/thread/:thread_id' do 68 69 assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } 69 70 assert_simply_restful_for :comments, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } 70 71 end 71 72 end 72 73 73 74 def test_with_name_prefix 74 75 with_restful_routing :messages, :name_prefix => 'post_' do 75 76 assert_simply_restful_for :messages, :name_prefix => 'post_' … … 78 79 79 80 def test_with_collection_action 80 81 rss_options = {:action => 'rss'} 81 rss_path = "/messages ;rss"82 rss_path = "/messages/rss" 82 83 actions = { 'a' => :put, 'b' => :post, 'c' => :delete } 83 84 84 85 with_restful_routing :messages, :collection => { :rss => :get }.merge(actions) do … … 86 87 assert_routing rss_path, options.merge(rss_options) 87 88 88 89 actions.each do |action, method| 89 assert_recognizes(options.merge(:action => action), :path => "/messages ;#{action}", :method => method)90 assert_recognizes(options.merge(:action => action), :path => "/messages/#{action}", :method => method) 90 91 end 91 92 end 92 93 93 94 assert_restful_named_routes_for :messages do |options| 94 95 assert_named_route rss_path, :rss_messages_path, rss_options 95 96 actions.keys.each do |action| 96 assert_named_route "/messages ;#{action}", "#{action}_messages_path", :action => action97 assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action 97 98 end 98 99 end 99 100 end … … 103 104 [:put, :post].each do |method| 104 105 with_restful_routing :messages, :member => { :mark => method } do 105 106 mark_options = {:action => 'mark', :id => '1'} 106 mark_path = "/messages/1 ;mark"107 mark_path = "/messages/1/mark" 107 108 assert_restful_routes_for :messages do |options| 108 109 assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) 109 110 end … … 120 121 with_restful_routing :messages, :member => { :mark => method, :unmark => method } do 121 122 %w(mark unmark).each do |action| 122 123 action_options = {:action => action, :id => '1'} 123 action_path = "/messages/1 ;#{action}"124 action_path = "/messages/1/#{action}" 124 125 assert_restful_routes_for :messages do |options| 125 126 assert_recognizes(options.merge(action_options), :path => action_path, :method => method) 126 127 end … … 136 137 def test_with_new_action 137 138 with_restful_routing :messages, :new => { :preview => :post } do 138 139 preview_options = {:action => 'preview'} 139 preview_path = "/messages/new ;preview"140 preview_path = "/messages/new/preview" 140 141 assert_restful_routes_for :messages do |options| 141 142 assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) 142 143 end … … 178 179 assert_simply_restful_for :threads 179 180 assert_simply_restful_for :messages, 180 181 :path_prefix => 'threads/1/', 182 :name_prefix => 'thread_', 181 183 :options => { :thread_id => '1' } 182 184 assert_simply_restful_for :comments, 183 185 :path_prefix => 'threads/1/messages/2/', 186 :name_prefix => 'thread_message_', 184 187 :options => { :thread_id => '1', :message_id => '2' } 185 188 end 186 189 end … … 217 220 admin.resource :account 218 221 end 219 222 end 220 223 221 224 assert_singleton_restful_for :admin 222 assert_singleton_restful_for :account, :path_prefix => 'admin/' 225 assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_' 223 226 end 224 227 end 225 228 … … 227 230 [:put, :post].each do |method| 228 231 with_singleton_resources :account, :member => { :reset => method } do 229 232 reset_options = {:action => 'reset'} 230 reset_path = "/account ;reset"233 reset_path = "/account/reset" 231 234 assert_singleton_routes_for :account do |options| 232 235 assert_recognizes(options.merge(reset_options), :path => reset_path, :method => method) 233 236 end … … 244 247 with_singleton_resources :account, :member => { :reset => method, :disable => method } do 245 248 %w(reset disable).each do |action| 246 249 action_options = {:action => action} 247 action_path = "/account ;#{action}"250 action_path = "/account/#{action}" 248 251 assert_singleton_routes_for :account do |options| 249 252 assert_recognizes(options.merge(action_options), :path => action_path, :method => method) 250 253 end … … 264 267 account.resources :messages 265 268 end 266 269 end 267 270 268 271 assert_singleton_restful_for :account 269 assert_simply_restful_for :messages, :path_prefix => 'account/' 272 assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_' 270 273 end 271 274 end 272 275 … … 279 282 end 280 283 281 284 assert_singleton_restful_for :account, :path_prefix => '7/', :options => { :site_id => '7' } 282 assert_simply_restful_for :messages, :path_prefix => '7/account/', : options => { :site_id => '7' }285 assert_simply_restful_for :messages, :path_prefix => '7/account/', :name_prefix => 'account_', :options => { :site_id => '7' } 283 286 end 284 287 end 285 288 286 289 def test_should_nest_singleton_resource_in_resources 287 290 with_routing do |set| 288 291 set.draw do |map| … … 290 293 thread.resource :admin 291 294 end 292 295 end 293 296 294 297 assert_simply_restful_for :threads 295 assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', : options => { :thread_id => '5' }298 assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' } 296 299 end 297 300 end 298 301 … … 312 315 end 313 316 end 314 317 318 def test_resource_action_separator 319 with_routing do |set| 320 set.draw do |map| 321 map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 322 map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 323 end 324 325 action_separator = ActionController::Base.resource_action_separator 326 327 assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 328 assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {} 329 assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} 330 assert_named_route "/threads/1/messages/new#{action_separator}preview", "preview_new_thread_message_path", {} 331 assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 332 assert_named_route "/admin/account#{action_separator}login", "login_admin_account_path", {} 333 assert_named_route "/admin/account/new", "new_admin_account_path", {} 334 assert_named_route "/admin/account/new#{action_separator}preview", "preview_new_admin_account_path", {} 335 end 336 end 337 338 def test_new_style_named_routes_for_resource 339 with_routing do |set| 340 set.draw do |map| 341 map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 342 end 343 assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 344 assert_named_route "/threads/1/messages/search", "search_thread_messages_path", {} 345 assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} 346 assert_named_route "/threads/1/messages/new/preview", "preview_new_thread_message_path", {} 347 end 348 end 349 350 def test_new_style_named_routes_for_singleton_resource 351 with_routing do |set| 352 set.draw do |map| 353 map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 354 end 355 assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 356 assert_named_route "/admin/account/login", "login_admin_account_path", {} 357 assert_named_route "/admin/account/new", "new_admin_account_path", {} 358 assert_named_route "/admin/account/new/preview", "preview_new_admin_account_path", {} 359 end 360 end 361 362 def test_should_add_deprecated_named_routes_for_resource 363 with_routing do |set| 364 set.draw do |map| 365 map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 366 end 367 assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 368 assert_deprecated do 369 assert_named_route "/threads/1/messages/search", "thread_search_messages_path", {} 370 assert_named_route "/threads/1/messages/new", "thread_new_message_path", {} 371 assert_named_route "/threads/1/messages/new/preview", "thread_preview_new_message_path", {} 372 end 373 end 374 end 375 376 def test_should_add_deprecated_named_routes_for_singleton_resource 377 with_routing do |set| 378 set.draw do |map| 379 map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 380 end 381 assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 382 assert_deprecated do 383 assert_named_route "/admin/account/login", "admin_login_account_path", {} 384 assert_named_route "/admin/account/new", "admin_new_account_path", {} 385 assert_named_route "/admin/account/new/preview", "admin_preview_new_account_path", {} 386 end 387 end 388 end 389 390 def test_should_add_deprecated_named_routes_for_nested_resources 391 with_routing do |set| 392 set.draw do |map| 393 map.resources :threads do |map| 394 map.resources :messages do |map| 395 map.resources :comments 396 end 397 end 398 end 399 400 assert_simply_restful_for :threads 401 assert_simply_restful_for :messages, 402 :path_prefix => 'threads/1/', 403 :name_prefix => 'thread_', 404 :options => { :thread_id => '1' } 405 assert_simply_restful_for :comments, 406 :path_prefix => 'threads/1/messages/2/', 407 :name_prefix => 'thread_message_', 408 :options => { :thread_id => '1', :message_id => '2' } 409 410 assert_deprecated do 411 assert_named_route "/threads/1/messages", "messages_path", {} 412 assert_named_route "/threads/1/messages/1", "message_path", {:thread_id => '1', :id => '1'} 413 assert_named_route "/threads/1/messages/new", "new_message_path", {:thread_id => '1'} 414 assert_named_route "/threads/1/messages/1/edit", "edit_message_path", {:thread_id => '1', :id => '1'} 415 end 416 end 417 end 418 419 def test_should_add_deprecated_named_routes_for_nested_singleton_resources 420 with_routing do |set| 421 set.draw do |map| 422 map.resource :admin do |admin| 423 admin.resource :account 424 end 425 end 426 427 assert_singleton_restful_for :admin 428 assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_' 429 430 assert_deprecated do 431 assert_named_route "/admin/account", "account_path", {} 432 assert_named_route "/admin/account/new", "new_account_path", {} 433 assert_named_route "/admin/account/edit", "edit_account_path", {} 434 end 435 end 436 end 437 438 def test_should_add_deprecated_named_routes_for_nested_resources_in_singleton_resource 439 with_routing do |set| 440 set.draw do |map| 441 map.resource :account do |account| 442 account.resources :messages 443 end 444 end 445 446 assert_singleton_restful_for :account 447 assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_' 448 449 assert_deprecated do 450 assert_named_route "/account/messages", "messages_path", {} 451 assert_named_route "/account/messages/1", "message_path", {:id => '1'} 452 assert_named_route "/account/messages/new", "new_message_path", {} 453 assert_named_route "/account/messages/1/edit", "edit_message_path", {:id => '1'} 454 end 455 end 456 end 457 458 def test_should_add_deprecated_named_routes_for_nested_singleton_resource_in_resources 459 with_routing do |set| 460 set.draw do |map| 461 map.resources :threads do |thread| 462 thread.resource :admin 463 end 464 end 465 466 assert_simply_restful_for :threads 467 assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' } 468 469 assert_deprecated do 470 assert_named_route "/threads/5/admin", "admin_path", {} 471 assert_named_route "/threads/5/admin/new", "new_admin_path", {} 472 assert_named_route "/threads/5/admin/edit", "edit_admin_path", {} 473 end 474 end 475 end 476 477 def test_should_add_deprecated_formatted_routes 478 with_routing do |set| 479 set.draw do |map| 480 map.resources :products, :collection => { :specials => :get }, :member => { :thumbnail => :get } 481 map.resource :account, :member => { :icon => :get } 482 end 483 assert_restful_routes_for :products do |options| 484 assert_recognizes options.merge({ :action => 'specials', :format => 'xml' }), :path => '/products.xml;specials', :method => :get 485 assert_recognizes options.merge({ :action => 'thumbnail', :format => 'jpg', :id => '1' }), :path => '/products/1.jpg;thumbnail', :method => :get 486 end 487 assert_singleton_restful_for :account do |options| 488 assert_recognizes options.merge({ :action => 'icon', :format => 'jpg' }), :path => '/account.jpg;icon', :method => :get 489 end 490 end 491 end 492 315 493 protected 316 494 def with_restful_routing(*args) 317 495 with_routing do |set| … … 319 497 yield 320 498 end 321 499 end 322 500 323 501 def with_singleton_resources(*args) 324 502 with_routing do |set| 325 503 set.draw { |map| map.resource(*args) } … … 344 522 collection_path = "/#{options[:path_prefix]}#{controller_name}" 345 523 member_path = "#{collection_path}/1" 346 524 new_path = "#{collection_path}/new" 347 edit_member_path = "#{member_path} ;edit"348 formatted_edit_member_path = "#{member_path} .xml;edit"525 edit_member_path = "#{member_path}/edit" 526 formatted_edit_member_path = "#{member_path}/edit.xml" 349 527 350 528 with_options(options[:options]) do |controller| 351 529 controller.assert_routing collection_path, :action => 'index' … … 395 573 name_prefix = options[:name_prefix] 396 574 397 575 assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options] 398 assert_named_route "#{full_prefix}/new", " #{name_prefix}new_#{singular_name}_path", options[:options]576 assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options] 399 577 assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1') 400 assert_named_route "#{full_prefix}/1 ;edit", "#{name_prefix}edit_#{singular_name}_path", options[:options].merge(:id => '1')578 assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1') 401 579 assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml') 402 assert_named_route "#{full_prefix}/new.xml", "formatted_ #{name_prefix}new_#{singular_name}_path", options[:options].merge( :format => 'xml')580 assert_named_route "#{full_prefix}/new.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml') 403 581 assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') 404 assert_named_route "#{full_prefix}/1 .xml;edit", "formatted_#{name_prefix}edit_#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')582 assert_named_route "#{full_prefix}/1/edit.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') 405 583 yield options[:options] if block_given? 406 584 end 407 585 … … 410 588 411 589 full_path = "/#{options[:path_prefix]}#{singleton_name}" 412 590 new_path = "#{full_path}/new" 413 edit_path = "#{full_path} ;edit"414 formatted_edit_path = "#{full_path} .xml;edit"591 edit_path = "#{full_path}/edit" 592 formatted_edit_path = "#{full_path}/edit.xml" 415 593 416 594 with_options options[:options] do |controller| 417 595 controller.assert_routing full_path, :action => 'show' … … 448 626 options[:options].delete :action 449 627 450 628 full_path = "/#{options[:path_prefix]}#{singleton_name}" 629 full_name = "#{options[:name_prefix]}#{singleton_name}" 451 630 452 assert_named_route "#{full_path}", "#{ singleton_name}_path", options[:options]453 assert_named_route "#{full_path}/new", "new_#{ singleton_name}_path", options[:options]454 assert_named_route "#{full_path} ;edit", "edit_#{singleton_name}_path", options[:options]455 assert_named_route "#{full_path}.xml", "formatted_#{ singleton_name}_path", options[:options].merge(:format => 'xml')456 assert_named_route "#{full_path}/new.xml", "formatted_new_#{ singleton_name}_path", options[:options].merge(:format => 'xml')457 assert_named_route "#{full_path} .xml;edit", "formatted_edit_#{singleton_name}_path", options[:options].merge(:format => 'xml')631 assert_named_route "#{full_path}", "#{full_name}_path", options[:options] 632 assert_named_route "#{full_path}/new", "new_#{full_name}_path", options[:options] 633 assert_named_route "#{full_path}/edit", "edit_#{full_name}_path", options[:options] 634 assert_named_route "#{full_path}.xml", "formatted_#{full_name}_path", options[:options].merge(:format => 'xml') 635 assert_named_route "#{full_path}/new.xml", "formatted_new_#{full_name}_path", options[:options].merge(:format => 'xml') 636 assert_named_route "#{full_path}/edit.xml", "formatted_edit_#{full_name}_path", options[:options].merge(:format => 'xml') 458 637 end 459 638 460 639 def assert_named_route(expected, route, options) -
actionpack/lib/action_controller/base.rb
old new 292 292 # Turn on +ignore_missing_templates+ if you want to unit test actions without making the associated templates. 293 293 cattr_accessor :ignore_missing_templates 294 294 295 # Controls the resource action separator 296 @@resource_action_separator = "/" 297 cattr_accessor :resource_action_separator 298 295 299 # Holds the request object that's primarily used to get environment variables through access like 296 300 # <tt>request.env["REQUEST_URI"]</tt>. 297 301 attr_internal :request -
actionpack/lib/action_controller/resources.rb
old new 9 9 def initialize(entities, options) 10 10 @plural = entities 11 11 @singular = options[:singular] || plural.to_s.singularize 12 12 13 13 @options = options 14 14 15 15 arrange_actions 16 16 add_default_actions 17 17 set_prefixes 18 18 end 19 19 20 20 def controller 21 21 @controller ||= (options[:controller] || plural).to_s 22 22 end 23 23 24 24 def path 25 25 @path ||= "#{path_prefix}/#{plural}" 26 26 end 27 27 28 28 def new_path 29 29 @new_path ||= "#{path}/new" 30 30 end 31 31 32 32 def member_path 33 33 @member_path ||= "#{path}/:id" 34 34 end 35 35 36 36 def nesting_path_prefix 37 37 @nesting_path_prefix ||= "#{path}/:#{singular}_id" 38 38 end 39 39 40 def deprecate_name_prefix? 41 options[:deprecate_name_prefix] || false 42 end 43 44 def nesting_name_prefix 45 "#{name_prefix}#{singular}_" 46 end 47 48 def action_separator 49 @action_separator ||= Base.resource_action_separator 50 end 51 40 52 protected 41 53 def arrange_actions 42 54 @collection_methods = arrange_actions_by_methods(options.delete(:collection)) 43 55 @member_methods = arrange_actions_by_methods(options.delete(:member)) 44 56 @new_methods = arrange_actions_by_methods(options.delete(:new)) 45 57 end 46 58 47 59 def add_default_actions 48 60 add_default_action(member_methods, :get, :edit) 49 61 add_default_action(new_methods, :get, :new) … … 60 72 flipped_hash 61 73 end 62 74 end 63 75 64 76 def add_default_action(collection, method, action) 65 77 (collection[method] ||= []).unshift(action) 66 78 end … … 300 312 map_member_actions(map, resource) 301 313 302 314 if block_given? 303 with_options(:path_prefix => resource.nesting_path_prefix, &block) 315 options = {:path_prefix => resource.nesting_path_prefix} 316 options.merge!({:name_prefix => resource.nesting_name_prefix, :deprecate_name_prefix => true}) unless options.key?(:name_prefix) 317 with_options(options, &block) 304 318 end 305 319 end 306 320 end … … 315 329 map_member_actions(map, resource) 316 330 317 331 if block_given? 318 with_options(:path_prefix => resource.nesting_path_prefix, &block) 332 options = {:path_prefix => resource.nesting_path_prefix} 333 options.merge!({:name_prefix => resource.nesting_name_prefix, :deprecate_name_prefix => true}) unless options.key?(:name_prefix) 334 with_options(options, &block) 319 335 end 320 336 end 321 337 end … … 324 340 resource.collection_methods.each do |method, actions| 325 341 actions.each do |action| 326 342 action_options = action_options_for(action, resource, method) 327 map.named_route("#{resource.name_prefix}#{action}_#{resource.plural}", "#{resource.path};#{action}", action_options) 328 map.named_route("formatted_#{resource.name_prefix}#{action}_#{resource.plural}", "#{resource.path}.:format;#{action}", action_options) 343 344 unless resource.name_prefix.blank? 345 map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.name_prefix}#{action}_#{resource.plural}") 346 map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.name_prefix}#{action}_#{resource.plural}") 347 end 348 349 if resource.deprecate_name_prefix? 350 map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{action}_#{resource.plural}") 351 map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{action}_#{resource.plural}") 352 end 353 354 map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options) 355 map.connect("#{resource.path};#{action}", action_options) 356 map.connect("#{resource.path}.:format;#{action}", action_options) 357 map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options) 329 358 end 330 359 end 331 360 end … … 335 364 map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, index_action_options) 336 365 map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", index_action_options) 337 366 367 if resource.deprecate_name_prefix? 368 map.deprecated_named_route("#{resource.name_prefix}#{resource.plural}", "#{resource.plural}") 369 map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.plural}") 370 end 371 338 372 create_action_options = action_options_for("create", resource) 339 373 map.connect(resource.path, create_action_options) 340 374 map.connect("#{resource.path}.:format", create_action_options) … … 351 385 actions.each do |action| 352 386 action_options = action_options_for(action, resource, method) 353 387 if action == :new 354 map.named_route("#{resource.name_prefix}new_#{resource.singular}", resource.new_path, action_options) 355 map.named_route("formatted_#{resource.name_prefix}new_#{resource.singular}", "#{resource.new_path}.:format", action_options) 388 389 unless resource.name_prefix.blank? 390 map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}new_#{resource.singular}") 391 map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}new_#{resource.singular}") 392 end 393 394 if resource.deprecate_name_prefix? 395 map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "new_#{resource.singular}") 396 map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_new_#{resource.singular}") 397 end 398 399 map.named_route("new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options) 400 map.named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options) 401 356 402 else 357 map.named_route("#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path};#{action}", action_options) 358 map.named_route("formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path}.:format;#{action}", action_options) 403 404 unless resource.name_prefix.blank? 405 map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}#{action}_new_#{resource.singular}") 406 map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}") 407 end 408 409 if resource.deprecate_name_prefix? 410 map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{action}_new_#{resource.singular}") 411 map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_new_#{resource.singular}") 412 end 413 414 map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options) 415 map.connect("#{resource.new_path};#{action}", action_options) 416 map.connect("#{resource.new_path}.:format;#{action}", action_options) 417 map.named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options) 418 359 419 end 360 420 end 361 421 end … … 365 425 resource.member_methods.each do |method, actions| 366 426 actions.each do |action| 367 427 action_options = action_options_for(action, resource, method) 368 map.named_route("#{resource.name_prefix}#{action}_#{resource.singular}", "#{resource.member_path};#{action}", action_options) 369 map.named_route("formatted_#{resource.name_prefix}#{action}_#{resource.singular}", "#{resource.member_path}.:format;#{action}",action_options) 428 429 unless resource.name_prefix.blank? 430 map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}#{action}_#{resource.singular}") 431 map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}#{action}_#{resource.singular}") 432 end 433 434 if resource.deprecate_name_prefix? 435 map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{action}_#{resource.singular}") 436 map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{action}_#{resource.singular}") 437 end 438 439 map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options) 440 map.connect("#{resource.member_path};#{action}", action_options) 441 map.connect("#{resource.member_path}.:format;#{action}", action_options) 442 map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format", action_options) 443 370 444 end 371 445 end 372 446 … … 374 448 map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options) 375 449 map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", show_action_options) 376 450 451 if resource.deprecate_name_prefix? 452 map.deprecated_named_route("#{resource.name_prefix}#{resource.singular}", "#{resource.singular}") 453 map.deprecated_named_route("formatted_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.singular}") 454 end 455 377 456 update_action_options = action_options_for("update", resource) 378 457 map.connect(resource.member_path, update_action_options) 379 458 map.connect("#{resource.member_path}.:format", update_action_options) -
actionpack/lib/action_controller/routing.rb
old new 989 989 def named_route(name, path, options = {}) 990 990 @set.add_named_route(name, path, options) 991 991 end 992 993 def deprecated_named_route(name, deprecated_name, options = {}) 994 @set.add_deprecated_named_route(name, deprecated_name) 995 end 992 996 993 997 # Added deprecation notice for anyone who already added a named route called "root". 994 998 # It'll be used as a shortcut for map.connect '' in Rails 2.0. … … 1019 1023 def clear! 1020 1024 @routes = {} 1021 1025 @helpers = [] 1022 1026 1023 1027 @module ||= Module.new 1024 1028 @module.instance_methods.each do |selector| 1025 1029 @module.send :remove_method, selector … … 1055 1059 def install(destinations = [ActionController::Base, ActionView::Base]) 1056 1060 Array(destinations).each { |dest| dest.send :include, @module } 1057 1061 end 1062 1063 def define_deprecated_named_route_methods(name, deprecated_name) 1058 1064 1065 [:url, :path].each do |kind| 1066 @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks 1067 1068 def #{url_helper_name(deprecated_name, kind)}(*args) 1069 1070 ActiveSupport::Deprecation.warn( 1071 'The named route "#{url_helper_name(deprecated_name, kind)}" uses a format that has been deprecated. ' + 1072 'You should use "#{url_helper_name(name, kind)}" instead.', caller 1073 ) 1074 1075 send :#{url_helper_name(name, kind)}, *args 1076 1077 end 1078 1079 def #{hash_access_name(deprecated_name, kind)}(*args) 1080 1081 ActiveSupport::Deprecation.warn( 1082 'The named route "#{hash_access_name(deprecated_name, kind)}" uses a format that has been deprecated. ' + 1083 'You should use "#{hash_access_name(name, kind)}" instead.', caller 1084 ) 1085 1086 send :#{hash_access_name(name, kind)}, *args 1087 1088 end 1089 1090 end_eval 1091 end 1092 1093 end 1094 1059 1095 private 1060 1096 def url_helper_name(name, kind = :url) 1061 1097 :"#{name}_#{kind}" … … 1177 1213 def add_named_route(name, path, options = {}) 1178 1214 named_routes[name] = add_route(path, options) 1179 1215 end 1216 1217 def add_deprecated_named_route(name, deprecated_name) 1218 named_routes.define_deprecated_named_route_methods(name, deprecated_name) 1219 end 1180 1220 1181 1221 def options_as_params(options) 1182 1222 # If an explicit :controller was given, always make :action explicit