Changeset 6922
- Timestamp:
- 06/01/07 04:40:30 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/resources.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/resources_test.rb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6920 r6922 1 1 *SVN* 2 3 * Routing: map.resource :logo routes to LogosController so the controller may be reused for multiple nestings or namespaces. [Jeremy Kemper] 2 4 3 5 * render :partial recognizes Active Record associations as Arrays. #8538 [kamal] trunk/actionpack/lib/action_controller/resources.rb
r6865 r6922 50 50 51 51 def initialize(entities, options) 52 @plural = entities53 @singular = options[:singular] || plural.to_s.singularize52 @plural ||= entities 53 @singular ||= options[:singular] || plural.to_s.singularize 54 54 55 55 @options = options … … 123 123 class SingletonResource < Resource #:nodoc: 124 124 def initialize(entity, options) 125 @plural = @singular = entity 126 @options = options 127 arrange_actions 128 add_default_actions 129 set_prefixes 125 @singular = @plural = entity 126 options[:controller] ||= @singular.to_s.pluralize 127 super 130 128 end 131 129 trunk/actionpack/test/controller/resources_test.rb
r6862 r6922 11 11 class CommentsController < ResourcesController; end 12 12 class AuthorsController < ResourcesController; end 13 class Logo Controller < ResourcesController; end14 15 class Account Controller < ResourcesController; end13 class LogosController < ResourcesController; end 14 15 class AccountsController < ResourcesController; end 16 16 class AdminController < ResourcesController; end 17 17 … … 19 19 class ProductsController < ResourcesController; end 20 20 class TagsController < ResourcesController; end 21 class Manufacturer Controller < ResourcesController; end21 class ManufacturersController < ResourcesController; end 22 22 23 23 module Admin … … 264 264 265 265 def test_should_create_multiple_singleton_resource_routes 266 with_singleton_resources :account, : admindo266 with_singleton_resources :account, :logo do 267 267 assert_singleton_restful_for :account 268 assert_singleton_restful_for : admin268 assert_singleton_restful_for :logo 269 269 end 270 270 end … … 273 273 with_routing do |set| 274 274 set.draw do |map| 275 map.resource :admin do |admin|275 map.resource :admin, :controller => 'admin' do |admin| 276 276 admin.resource :account 277 277 end 278 278 end 279 279 280 assert_singleton_restful_for :admin 280 assert_singleton_restful_for :admin, :controller => 'admin' 281 281 assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => 'admin/' 282 282 end … … 370 370 set.draw do |map| 371 371 map.resources :threads do |thread| 372 thread.resource :admin 372 thread.resource :admin, :controller => 'admin' 373 373 end 374 374 end 375 375 376 376 assert_simply_restful_for :threads 377 assert_singleton_restful_for :admin, : name_prefix => 'thread_', :path_prefix => 'threads/5/', :options => { :thread_id => '5' }377 assert_singleton_restful_for :admin, :controller => 'admin', :name_prefix => 'thread_', :path_prefix => 'threads/5/', :options => { :thread_id => '5' } 378 378 end 379 379 end … … 429 429 430 430 assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/' 431 assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturer ", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' }431 assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturers", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' } 432 432 end 433 433 end … … 556 556 def assert_singleton_routes_for(singleton_name, options = {}) 557 557 options[:options] ||= {} 558 options[:options][:controller] = options[:controller] || singleton_name.to_s 558 options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize 559 559 560 560 full_path = "/#{options[:path_prefix]}#{singleton_name}" … … 590 590 591 591 def assert_singleton_named_routes_for(singleton_name, options = {}) 592 (options[:options] ||= {})[:controller] ||= singleton_name.to_s 592 (options[:options] ||= {})[:controller] ||= singleton_name.to_s.pluralize 593 593 @controller = "#{options[:options][:controller].camelize}Controller".constantize.new 594 594 @request = ActionController::TestRequest.new