Changeset 8785
- Timestamp:
- 02/02/08 05:57:16 (10 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/resources.rb (modified) (4 diffs)
- trunk/actionpack/test/controller/resources_test.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8782 r8785 1 1 *SVN* 2 3 * Introduce map.resources :cards, :as => 'tarjetas' to use a custom resource name in the URL: cards_path == '/tarjetas'. #10578 [blj] 2 4 3 5 * TestSession supports indifferent access. #7372 [tamc, Arsen7, mhackett, julik, jean.helou] trunk/actionpack/lib/action_controller/resources.rb
r8028 r8785 45 45 class Resource #:nodoc: 46 46 attr_reader :collection_methods, :member_methods, :new_methods 47 attr_reader :path_prefix, :name_prefix 47 attr_reader :path_prefix, :name_prefix, :path_segment 48 48 attr_reader :plural, :singular 49 49 attr_reader :options … … 52 52 @plural ||= entities 53 53 @singular ||= options[:singular] || plural.to_s.singularize 54 @path_segment = options.delete(:as) || @plural 54 55 55 56 @options = options … … 76 77 77 78 def path 78 @path ||= "#{path_prefix}/#{p lural}"79 @path ||= "#{path_prefix}/#{path_segment}" 79 80 end 80 81 … … 237 238 # * <tt>:requirements</tt> - set custom routing parameter requirements. 238 239 # * <tt>:conditions</tt> - specify custom routing recognition conditions. Resources sets the :method value for the method-specific routes. 240 # * <tt>:as</tt> - specify a different resource name to use in the URL path. For example: 241 # # products_path == '/productos' 242 # map.resources :products, :as => 'productos' do |product| 243 # # product_reviews_path(product) == '/productos/1234/comentarios' 244 # product.resources :product_reviews, :as => 'comentarios' 245 # end 246 # 239 247 # * <tt>:path_prefix</tt> - set a prefix to the routes with required route variables. 240 248 # trunk/actionpack/test/controller/resources_test.rb
r8564 r8785 610 610 end 611 611 612 def test_with_path_segment 613 with_restful_routing :messages, :as => 'reviews' do 614 assert_simply_restful_for :messages, :as => 'reviews' 615 end 616 end 617 618 def test_multiple_with_path_segment_and_controller 619 with_routing do |set| 620 set.draw do |map| 621 map.resources :products do |products| 622 products.resources :product_reviews, :as => 'reviews', :controller => 'messages' 623 end 624 map.resources :tutors do |tutors| 625 tutors.resources :tutor_reviews, :as => 'reviews', :controller => 'comments' 626 end 627 end 628 629 assert_simply_restful_for :product_reviews, :controller=>'messages', :as => 'reviews', :name_prefix => 'product_', :path_prefix => 'products/1/', :options => {:product_id => '1'} 630 assert_simply_restful_for :tutor_reviews,:controller=>'comments', :as => 'reviews', :name_prefix => 'tutor_', :path_prefix => 'tutors/1/', :options => {:tutor_id => '1'} 631 end 632 end 633 634 def test_with_path_segment_path_prefix_requirements 635 expected_options = {:controller => 'messages', :action => 'show', :thread_id => '1.1.1', :id => '1'} 636 with_restful_routing :messages, :as => 'comments',:path_prefix => '/thread/:thread_id', :requirements => { :thread_id => /[0-9]\.[0-9]\.[0-9]/ } do 637 assert_recognizes(expected_options, :path => 'thread/1.1.1/comments/1', :method => :get) 638 end 639 end 640 612 641 protected 613 642 def with_restful_routing(*args) … … 640 669 options[:options][:controller] = options[:controller] || controller_name.to_s 641 670 642 collection_path = "/#{options[:path_prefix]}#{ controller_name}"671 collection_path = "/#{options[:path_prefix]}#{options[:as] || controller_name}" 643 672 member_path = "#{collection_path}/1" 644 673 new_path = "#{collection_path}/new" … … 693 722 options[:options].delete :action 694 723 695 full_prefix = "/#{options[:path_prefix]}#{ controller_name}"724 full_prefix = "/#{options[:path_prefix]}#{options[:as] || controller_name}" 696 725 name_prefix = options[:name_prefix] 697 726 698 727 assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options] 699 728 assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml') … … 713 742 options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize 714 743 715 full_path = "/#{options[:path_prefix]}#{ singleton_name}"744 full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}" 716 745 new_path = "#{full_path}/new" 717 746 edit_path = "#{full_path}/edit" … … 752 781 options[:options].delete :action 753 782 754 full_path = "/#{options[:path_prefix]}#{ singleton_name}"783 full_path = "/#{options[:path_prefix]}#{options[:as] || singleton_name}" 755 784 name_prefix = options[:name_prefix] 756 785