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

Changeset 7600

Show
Ignore:
Timestamp:
09/23/07 22:03:09 (1 year ago)
Author:
bitsweat
Message:

Revert [7414] which rearranged stable resource URLs. References #8558.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1-2-stable/actionpack/lib/action_controller/base.rb

    r7414 r7600  
    293293    cattr_accessor :ignore_missing_templates 
    294294 
    295     # Controls the resource action separator 
    296     @@resource_action_separator = ";" 
    297     cattr_accessor :resource_action_separator 
    298  
    299295    # Holds the request object that's primarily used to get environment variables through access like 
    300296    # <tt>request.env["REQUEST_URI"]</tt>. 
  • branches/1-2-stable/actionpack/lib/action_controller/resources.rb

    r7414 r7600  
    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  
    40       def action_separator 
    41         @action_separator ||= Base.resource_action_separator 
    42       end 
    43  
     39       
    4440      protected 
    4541        def arrange_actions 
     
    329325          actions.each do |action| 
    330326            action_options = action_options_for(action, resource, method) 
    331  
    332             unless resource.name_prefix.blank? 
    333               map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.name_prefix}#{action}_#{resource.plural}") 
    334               map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "formatted_#{resource.name_prefix}#{action}_#{resource.plural}") 
    335             end 
    336  
    337             map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}", action_options) 
    338             map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options) 
     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) 
    339329          end 
    340330        end 
     
    362352            action_options = action_options_for(action, resource, method) 
    363353            if action == :new 
    364  
    365               unless resource.name_prefix.blank? 
    366                 map.deprecated_named_route("new_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}new_#{resource.singular}") 
    367                 map.deprecated_named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}new_#{resource.singular}") 
    368               end 
    369  
    370               map.named_route("new_#{resource.name_prefix}#{resource.singular}", resource.new_path, action_options) 
    371               map.named_route("formatted_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options) 
    372  
     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) 
    373356            else 
    374  
    375               unless resource.name_prefix.blank? 
    376                 map.deprecated_named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}#{action}_new_#{resource.singular}") 
    377                 map.deprecated_named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}") 
    378               end 
    379  
    380               map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}", action_options) 
    381               map.named_route("formatted_#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options) 
    382  
     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) 
    383359            end 
    384360          end 
     
    390366          actions.each do |action| 
    391367            action_options = action_options_for(action, resource, method) 
    392  
    393             unless resource.name_prefix.blank? 
    394               map.deprecated_named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.name_prefix}#{action}_#{resource.singular}") 
    395               map.deprecated_named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "formatted_#{resource.name_prefix}#{action}_#{resource.singular}") 
    396             end 
    397  
    398             map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options) 
    399             map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format", action_options) 
    400  
     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) 
    401370          end 
    402371        end 
  • branches/1-2-stable/actionpack/lib/action_controller/routing.rb

    r7414 r7600  
    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 
    996992 
    997993        # Added deprecation notice for anyone who already added a named route called "root". 
     
    10241020          @routes = {} 
    10251021          @helpers = [] 
    1026  
     1022           
    10271023          @module ||= Module.new 
    10281024          @module.instance_methods.each do |selector| 
     
    10591055        def install(destinations = [ActionController::Base, ActionView::Base]) 
    10601056          Array(destinations).each { |dest| dest.send :include, @module } 
    1061         end 
    1062          
    1063         def define_deprecated_named_route_methods(name, deprecated_name) 
    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  
    10931057        end 
    10941058 
     
    12141178        named_routes[name] = add_route(path, options) 
    12151179      end 
    1216        
    1217       def add_deprecated_named_route(name, deprecated_name) 
    1218         named_routes.define_deprecated_named_route_methods(name, deprecated_name) 
    1219       end 
    12201180   
    12211181      def options_as_params(options) 
  • branches/1-2-stable/actionpack/test/controller/resources_test.rb

    r7414 r7600  
    6464  end 
    6565 
    66   def test_multiple_with_path_prefix 
     66  def test_multile_with_path_prefix 
    6767    with_restful_routing :messages, :comments, :path_prefix => '/thread/:thread_id' do 
    6868      assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } 
     
    313313  end 
    314314 
    315   def test_resource_action_separator 
    316     with_routing do |set| 
    317       set.draw do |map| 
    318         map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 
    319         map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 
    320       end 
    321        
    322       action_separator = ActionController::Base.resource_action_separator 
    323        
    324       assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 
    325       assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {} 
    326       assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} 
    327       assert_named_route "/threads/1/messages/new#{action_separator}preview", "preview_new_thread_message_path", {} 
    328       assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 
    329       assert_named_route "/admin/account#{action_separator}login", "login_admin_account_path", {} 
    330       assert_named_route "/admin/account/new", "new_admin_account_path", {} 
    331       assert_named_route "/admin/account/new#{action_separator}preview", "preview_new_admin_account_path", {} 
    332     end 
    333   end 
    334  
    335   def test_new_style_named_routes_for_resource 
    336     with_routing do |set| 
    337       set.draw do |map| 
    338         map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 
    339       end 
    340       assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 
    341       assert_named_route "/threads/1/messages;search", "search_thread_messages_path", {} 
    342       assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} 
    343       assert_named_route "/threads/1/messages/new;preview", "preview_new_thread_message_path", {} 
    344     end 
    345   end 
    346  
    347   def test_new_style_named_routes_for_singleton_resource 
    348     with_routing do |set| 
    349       set.draw do |map| 
    350         map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 
    351       end 
    352       assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 
    353       assert_named_route "/admin/account;login", "login_admin_account_path", {} 
    354       assert_named_route "/admin/account/new", "new_admin_account_path", {} 
    355       assert_named_route "/admin/account/new;preview", "preview_new_admin_account_path", {} 
    356     end 
    357   end 
    358  
    359   def test_should_add_deprecated_named_routes_for_resource 
    360     with_routing do |set| 
    361       set.draw do |map| 
    362         map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' 
    363       end 
    364       assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } 
    365       assert_deprecated do 
    366         assert_named_route "/threads/1/messages;search", "thread_search_messages_path", {} 
    367         assert_named_route "/threads/1/messages/new", "thread_new_message_path", {} 
    368         assert_named_route "/threads/1/messages/new;preview", "thread_preview_new_message_path", {} 
    369       end 
    370     end 
    371   end 
    372  
    373   def test_should_add_deprecated_named_routes_for_singleton_resource 
    374     with_routing do |set| 
    375       set.draw do |map| 
    376         map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' 
    377       end 
    378       assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' 
    379       assert_deprecated do 
    380         assert_named_route "/admin/account;login", "admin_login_account_path", {} 
    381         assert_named_route "/admin/account/new", "admin_new_account_path", {} 
    382         assert_named_route "/admin/account/new;preview", "admin_preview_new_account_path", {} 
    383       end 
    384     end 
    385   end 
    386  
    387315  protected 
    388316    def with_restful_routing(*args) 
     
    418346      new_path                   = "#{collection_path}/new" 
    419347      edit_member_path           = "#{member_path};edit" 
    420       formatted_edit_member_path = "#{member_path};edit.xml
     348      formatted_edit_member_path = "#{member_path}.xml;edit
    421349 
    422350      with_options(options[:options]) do |controller| 
     
    468396 
    469397      assert_named_route "#{full_prefix}",            "#{name_prefix}#{controller_name}_path",              options[:options] 
    470       assert_named_route "#{full_prefix}/new",        "new_#{name_prefix}#{singular_name}_path",            options[:options] 
     398      assert_named_route "#{full_prefix}/new",        "#{name_prefix}new_#{singular_name}_path",            options[:options] 
    471399      assert_named_route "#{full_prefix}/1",          "#{name_prefix}#{singular_name}_path",                options[:options].merge(:id => '1') 
    472       assert_named_route "#{full_prefix}/1;edit",     "edit_#{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') 
    473401      assert_named_route "#{full_prefix}.xml",        "formatted_#{name_prefix}#{controller_name}_path",    options[:options].merge(            :format => 'xml') 
    474       assert_named_route "#{full_prefix}/new.xml",    "formatted_new_#{name_prefix}#{singular_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') 
    475403      assert_named_route "#{full_prefix}/1.xml",      "formatted_#{name_prefix}#{singular_name}_path",      options[:options].merge(:id => '1', :format => 'xml') 
    476       assert_named_route "#{full_prefix}/1;edit.xml", "formatted_edit_#{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') 
    477405      yield options[:options] if block_given? 
    478406    end 
     
    484412      new_path            = "#{full_path}/new" 
    485413      edit_path           = "#{full_path};edit" 
    486       formatted_edit_path = "#{full_path};edit.xml
     414      formatted_edit_path = "#{full_path}.xml;edit
    487415 
    488416      with_options options[:options] do |controller| 
     
    521449 
    522450      full_path = "/#{options[:path_prefix]}#{singleton_name}" 
    523       full_name = "#{options[:name_prefix]}#{singleton_name}" 
    524  
    525       assert_named_route "#{full_path}",          "#{full_name}_path",                options[:options] 
    526       assert_named_route "#{full_path}/new",      "new_#{full_name}_path",            options[:options] 
    527       assert_named_route "#{full_path};edit",     "edit_#{full_name}_path",           options[:options] 
    528       assert_named_route "#{full_path}.xml",      "formatted_#{full_name}_path",      options[:options].merge(:format => 'xml') 
    529       assert_named_route "#{full_path}/new.xml",  "formatted_new_#{full_name}_path",  options[:options].merge(:format => 'xml') 
    530       assert_named_route "#{full_path};edit.xml", "formatted_edit_#{full_name}_path", options[:options].merge(:format => 'xml') 
     451 
     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') 
    531458    end 
    532459