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

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  
    1010class MessagesController < ResourcesController; end 
    1111class CommentsController < ResourcesController; end 
    1212 
    13 class AccountController <  ResourcesController; end 
    14 class AdminController   <  ResourcesController; end 
     13class AccountController  < ResourcesController; end 
     14class AdminController    < ResourcesController; end 
     15class ProductsController < ResourcesController; end 
    1516 
    1617class ResourcesTest < Test::Unit::TestCase 
    1718  def test_should_arrange_actions 
     
    6364    end 
    6465  end 
    6566 
    66   def test_multile_with_path_prefix 
     67  def test_multiple_with_path_prefix 
    6768    with_restful_routing :messages, :comments, :path_prefix => '/thread/:thread_id' do 
    6869      assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } 
    6970      assert_simply_restful_for :comments, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } 
    7071    end 
    7172  end 
    72    
     73 
    7374  def test_with_name_prefix 
    7475    with_restful_routing :messages, :name_prefix => 'post_' do 
    7576      assert_simply_restful_for :messages, :name_prefix => 'post_' 
     
    7879 
    7980  def test_with_collection_action 
    8081    rss_options = {:action => 'rss'} 
    81     rss_path    = "/messages;rss" 
     82    rss_path    = "/messages/rss" 
    8283    actions = { 'a' => :put, 'b' => :post, 'c' => :delete } 
    8384 
    8485    with_restful_routing :messages, :collection => { :rss => :get }.merge(actions) do 
     
    8687        assert_routing rss_path, options.merge(rss_options) 
    8788 
    8889        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) 
    9091        end 
    9192      end 
    9293 
    9394      assert_restful_named_routes_for :messages do |options| 
    9495        assert_named_route rss_path, :rss_messages_path, rss_options 
    9596        actions.keys.each do |action| 
    96           assert_named_route "/messages;#{action}", "#{action}_messages_path", :action => action 
     97          assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action 
    9798        end 
    9899      end 
    99100    end 
     
    103104    [:put, :post].each do |method| 
    104105      with_restful_routing :messages, :member => { :mark => method } do 
    105106        mark_options = {:action => 'mark', :id => '1'} 
    106         mark_path    = "/messages/1;mark" 
     107        mark_path    = "/messages/1/mark" 
    107108        assert_restful_routes_for :messages do |options| 
    108109          assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) 
    109110        end 
     
    120121      with_restful_routing :messages, :member => { :mark => method, :unmark => method } do 
    121122        %w(mark unmark).each do |action| 
    122123          action_options = {:action => action, :id => '1'} 
    123           action_path    = "/messages/1;#{action}" 
     124          action_path    = "/messages/1/#{action}" 
    124125          assert_restful_routes_for :messages do |options| 
    125126            assert_recognizes(options.merge(action_options), :path => action_path, :method => method) 
    126127          end 
     
    136137  def test_with_new_action 
    137138    with_restful_routing :messages, :new => { :preview => :post } do 
    138139      preview_options = {:action => 'preview'} 
    139       preview_path    = "/messages/new;preview" 
     140      preview_path    = "/messages/new/preview" 
    140141      assert_restful_routes_for :messages do |options| 
    141142        assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) 
    142143      end 
     
    178179      assert_simply_restful_for :threads 
    179180      assert_simply_restful_for :messages, 
    180181        :path_prefix => 'threads/1/', 
     182        :name_prefix => 'thread_', 
    181183        :options => { :thread_id => '1' } 
    182184      assert_simply_restful_for :comments, 
    183185        :path_prefix => 'threads/1/messages/2/', 
     186        :name_prefix => 'thread_message_', 
    184187        :options => { :thread_id => '1', :message_id => '2' } 
    185188    end 
    186189  end 
     
    217220          admin.resource :account 
    218221        end 
    219222      end 
    220        
     223 
    221224      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_' 
    223226    end 
    224227  end 
    225228 
     
    227230    [:put, :post].each do |method| 
    228231      with_singleton_resources :account, :member => { :reset => method } do 
    229232        reset_options = {:action => 'reset'} 
    230         reset_path    = "/account;reset" 
     233        reset_path    = "/account/reset" 
    231234        assert_singleton_routes_for :account do |options| 
    232235          assert_recognizes(options.merge(reset_options), :path => reset_path, :method => method) 
    233236        end 
     
    244247      with_singleton_resources :account, :member => { :reset => method, :disable => method } do 
    245248        %w(reset disable).each do |action| 
    246249          action_options = {:action => action} 
    247           action_path    = "/account;#{action}" 
     250          action_path    = "/account/#{action}" 
    248251          assert_singleton_routes_for :account do |options| 
    249252            assert_recognizes(options.merge(action_options), :path => action_path, :method => method) 
    250253          end 
     
    264267          account.resources :messages 
    265268        end 
    266269      end 
    267        
     270 
    268271      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_' 
    270273    end 
    271274  end 
    272275 
     
    279282      end 
    280283 
    281284      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' } 
    283286    end 
    284287  end 
    285    
     288 
    286289  def test_should_nest_singleton_resource_in_resources 
    287290    with_routing do |set| 
    288291      set.draw do |map| 
     
    290293          thread.resource :admin 
    291294        end 
    292295      end 
    293        
     296 
    294297      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' } 
    296299    end 
    297300  end 
    298301 
     
    312315    end 
    313316  end 
    314317 
     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 
    315493  protected 
    316494    def with_restful_routing(*args) 
    317495      with_routing do |set| 
     
    319497        yield 
    320498      end 
    321499    end 
    322      
     500 
    323501    def with_singleton_resources(*args) 
    324502      with_routing do |set| 
    325503        set.draw { |map| map.resource(*args) } 
     
    344522      collection_path            = "/#{options[:path_prefix]}#{controller_name}" 
    345523      member_path                = "#{collection_path}/1" 
    346524      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
    349527 
    350528      with_options(options[:options]) do |controller| 
    351529        controller.assert_routing collection_path,            :action => 'index' 
     
    395573      name_prefix = options[:name_prefix] 
    396574 
    397575      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] 
    399577      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') 
    401579      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') 
    403581      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') 
    405583      yield options[:options] if block_given? 
    406584    end 
    407585 
     
    410588 
    411589      full_path           = "/#{options[:path_prefix]}#{singleton_name}" 
    412590      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
    415593 
    416594      with_options options[:options] do |controller| 
    417595        controller.assert_routing full_path,           :action => 'show' 
     
    448626      options[:options].delete :action 
    449627 
    450628      full_path = "/#{options[:path_prefix]}#{singleton_name}" 
     629      full_name = "#{options[:name_prefix]}#{singleton_name}" 
    451630 
    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') 
    458637    end 
    459638 
    460639    def assert_named_route(expected, route, options) 
  • actionpack/lib/action_controller/base.rb

    old new  
    292292    # Turn on +ignore_missing_templates+ if you want to unit test actions without making the associated templates. 
    293293    cattr_accessor :ignore_missing_templates 
    294294 
     295    # Controls the resource action separator 
     296    @@resource_action_separator = "/" 
     297    cattr_accessor :resource_action_separator 
     298 
    295299    # Holds the request object that's primarily used to get environment variables through access like 
    296300    # <tt>request.env["REQUEST_URI"]</tt>. 
    297301    attr_internal :request 
  • actionpack/lib/action_controller/resources.rb

    old new  
    99      def initialize(entities, options) 
    1010        @plural   = entities 
    1111        @singular = options[:singular] || plural.to_s.singularize 
    12          
     12 
    1313        @options = options 
    1414 
    1515        arrange_actions 
    1616        add_default_actions 
    1717        set_prefixes 
    1818      end 
    19        
     19 
    2020      def controller 
    2121        @controller ||= (options[:controller] || plural).to_s 
    2222      end 
    23        
     23 
    2424      def path 
    2525        @path ||= "#{path_prefix}/#{plural}" 
    2626      end 
    27        
     27 
    2828      def new_path 
    2929        @new_path ||= "#{path}/new" 
    3030      end 
    31        
     31 
    3232      def member_path 
    3333        @member_path ||= "#{path}/:id" 
    3434      end 
    35        
     35 
    3636      def nesting_path_prefix 
    3737        @nesting_path_prefix ||= "#{path}/:#{singular}_id" 
    3838      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 
    4052      protected 
    4153        def arrange_actions 
    4254          @collection_methods = arrange_actions_by_methods(options.delete(:collection)) 
    4355          @member_methods     = arrange_actions_by_methods(options.delete(:member)) 
    4456          @new_methods        = arrange_actions_by_methods(options.delete(:new)) 
    4557        end 
    46          
     58 
    4759        def add_default_actions 
    4860          add_default_action(member_methods, :get, :edit) 
    4961          add_default_action(new_methods, :get, :new) 
     
    6072            flipped_hash 
    6173          end 
    6274        end 
    63          
     75 
    6476        def add_default_action(collection, method, action) 
    6577          (collection[method] ||= []).unshift(action) 
    6678        end 
     
    300312          map_member_actions(map, resource) 
    301313 
    302314          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) 
    304318          end 
    305319        end 
    306320      end 
     
    315329          map_member_actions(map, resource) 
    316330 
    317331          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) 
    319335          end 
    320336        end 
    321337      end 
     
    324340        resource.collection_methods.each do |method, actions| 
    325341          actions.each do |action| 
    326342            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) 
    329358          end 
    330359        end 
    331360      end 
     
    335364        map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, index_action_options) 
    336365        map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", index_action_options) 
    337366 
     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 
    338372        create_action_options = action_options_for("create", resource) 
    339373        map.connect(resource.path, create_action_options) 
    340374        map.connect("#{resource.path}.:format", create_action_options) 
     
    351385          actions.each do |action| 
    352386            action_options = action_options_for(action, resource, method) 
    353387            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 
    356402            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 
    359419            end 
    360420          end 
    361421        end 
     
    365425        resource.member_methods.each do |method, actions| 
    366426          actions.each do |action| 
    367427            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 
    370444          end 
    371445        end 
    372446 
     
    374448        map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, show_action_options) 
    375449        map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", show_action_options) 
    376450 
     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 
    377456        update_action_options = action_options_for("update", resource) 
    378457        map.connect(resource.member_path, update_action_options) 
    379458        map.connect("#{resource.member_path}.:format", update_action_options) 
  • actionpack/lib/action_controller/routing.rb

    old new  
    989989        def named_route(name, path, options = {}) 
    990990          @set.add_named_route(name, path, options) 
    991991        end 
     992         
     993        def deprecated_named_route(name, deprecated_name, options = {}) 
     994          @set.add_deprecated_named_route(name, deprecated_name) 
     995        end 
    992996 
    993997        # Added deprecation notice for anyone who already added a named route called "root". 
    994998        # It'll be used as a shortcut for map.connect '' in Rails 2.0. 
     
    10191023        def clear! 
    10201024          @routes = {} 
    10211025          @helpers = [] 
    1022            
     1026 
    10231027          @module ||= Module.new 
    10241028          @module.instance_methods.each do |selector| 
    10251029            @module.send :remove_method, selector 
     
    10551059        def install(destinations = [ActionController::Base, ActionView::Base]) 
    10561060          Array(destinations).each { |dest| dest.send :include, @module } 
    10571061        end 
     1062         
     1063        def define_deprecated_named_route_methods(name, deprecated_name) 
    10581064 
     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 
    10591095        private 
    10601096          def url_helper_name(name, kind = :url) 
    10611097            :"#{name}_#{kind}" 
     
    11771213      def add_named_route(name, path, options = {}) 
    11781214        named_routes[name] = add_route(path, options) 
    11791215      end 
     1216       
     1217      def add_deprecated_named_route(name, deprecated_name) 
     1218        named_routes.define_deprecated_named_route_methods(name, deprecated_name) 
     1219      end 
    11801220   
    11811221      def options_as_params(options) 
    11821222        # If an explicit :controller was given, always make :action explicit