Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Routing: map.resource :logo routes to LogosController so the controll…

…er may be reused for multiple nestings or namespaces.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6922 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 8ce54793074ebd03bd2bf301c1f9ab7b180f054a 1 parent 507da04
@jeremy jeremy authored
View
2  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]
View
12 actionpack/lib/action_controller/resources.rb
@@ -49,8 +49,8 @@ class Resource #:nodoc:
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 @@ def add_default_action(collection, method, action)
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
View
24 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 @@ def test_should_create_singleton_resource_routes
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 @@ def test_should_nest_singleton_resource_in_resources
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 @@ def test_resource_has_one_in_namespace
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 @@ def assert_restful_named_routes_for(controller_name, singular_name = nil, option
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 @@ def assert_singleton_routes_for(singleton_name, options = {})
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
Please sign in to comment.
Something went wrong with that request. Please try again.