diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-01 04:40:30 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-01 04:40:30 +0000 |
commit | 8ce54793074ebd03bd2bf301c1f9ab7b180f054a (patch) | |
tree | febc16b9957c933204eb1bf36b8f4a09518158de /actionpack | |
parent | 507da04a149b44e20c5a0ba72a218fe1762b6baf (diff) | |
download | rails-8ce54793074ebd03bd2bf301c1f9ab7b180f054a.tar.gz rails-8ce54793074ebd03bd2bf301c1f9ab7b180f054a.tar.bz2 rails-8ce54793074ebd03bd2bf301c1f9ab7b180f054a.zip |
Routing: map.resource :logo routes to LogosController so the controller may be reused for multiple nestings or namespaces.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6922 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/resources.rb | 12 | ||||
-rw-r--r-- | actionpack/test/controller/resources_test.rb | 24 |
3 files changed, 19 insertions, 19 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 016eb72363..aea3f9e794 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Routing: map.resource :logo routes to LogosController so the controller may be reused for multiple nestings or namespaces. [Jeremy Kemper] + * render :partial recognizes Active Record associations as Arrays. #8538 [kamal] * Routing: drop semicolon and comma as route separators. [Jeremy Kemper] diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 45be7b6f11..a7e1a172cc 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -49,8 +49,8 @@ module ActionController attr_reader :options def initialize(entities, options) - @plural = entities - @singular = options[:singular] || plural.to_s.singularize + @plural ||= entities + @singular ||= options[:singular] || plural.to_s.singularize @options = options @@ -122,11 +122,9 @@ module ActionController class SingletonResource < Resource #:nodoc: def initialize(entity, options) - @plural = @singular = entity - @options = options - arrange_actions - add_default_actions - set_prefixes + @singular = @plural = entity + options[:controller] ||= @singular.to_s.pluralize + super end alias_method :member_path, :path diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 8149c02a9d..f405332fe3 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -10,15 +10,15 @@ class ThreadsController < ResourcesController; end class MessagesController < ResourcesController; end class CommentsController < ResourcesController; end class AuthorsController < ResourcesController; end -class LogoController < ResourcesController; end +class LogosController < ResourcesController; end -class AccountController < ResourcesController; end +class AccountsController < ResourcesController; end class AdminController < ResourcesController; end module Backoffice class ProductsController < ResourcesController; end class TagsController < ResourcesController; end - class ManufacturerController < ResourcesController; end + class ManufacturersController < ResourcesController; end module Admin class ProductsController < ResourcesController; end @@ -263,21 +263,21 @@ class ResourcesTest < Test::Unit::TestCase end def test_should_create_multiple_singleton_resource_routes - with_singleton_resources :account, :admin do + with_singleton_resources :account, :logo do assert_singleton_restful_for :account - assert_singleton_restful_for :admin + assert_singleton_restful_for :logo end end def test_should_create_nested_singleton_resource_routes with_routing do |set| set.draw do |map| - map.resource :admin do |admin| + map.resource :admin, :controller => 'admin' do |admin| admin.resource :account end end - assert_singleton_restful_for :admin + assert_singleton_restful_for :admin, :controller => 'admin' assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => 'admin/' end end @@ -369,12 +369,12 @@ class ResourcesTest < Test::Unit::TestCase with_routing do |set| set.draw do |map| map.resources :threads do |thread| - thread.resource :admin + thread.resource :admin, :controller => 'admin' end end assert_simply_restful_for :threads - assert_singleton_restful_for :admin, :name_prefix => 'thread_', :path_prefix => 'threads/5/', :options => { :thread_id => '5' } + assert_singleton_restful_for :admin, :controller => 'admin', :name_prefix => 'thread_', :path_prefix => 'threads/5/', :options => { :thread_id => '5' } end end @@ -428,7 +428,7 @@ class ResourcesTest < Test::Unit::TestCase end assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/' - assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturer", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' } + assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturers", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' } end end @@ -555,7 +555,7 @@ class ResourcesTest < Test::Unit::TestCase def assert_singleton_routes_for(singleton_name, options = {}) options[:options] ||= {} - options[:options][:controller] = options[:controller] || singleton_name.to_s + options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize full_path = "/#{options[:path_prefix]}#{singleton_name}" new_path = "#{full_path}/new" @@ -589,7 +589,7 @@ class ResourcesTest < Test::Unit::TestCase end def assert_singleton_named_routes_for(singleton_name, options = {}) - (options[:options] ||= {})[:controller] ||= singleton_name.to_s + (options[:options] ||= {})[:controller] ||= singleton_name.to_s.pluralize @controller = "#{options[:options][:controller].camelize}Controller".constantize.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new |