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

Changeset 6922

Show
Ignore:
Timestamp:
06/01/07 04:40:30 (3 years ago)
Author:
bitsweat
Message:

Routing: map.resource :logo routes to LogosController so the controller may be reused for multiple nestings or namespaces.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6920 r6922  
    11*SVN* 
     2 
     3* Routing: map.resource :logo routes to LogosController so the controller may be reused for multiple nestings or namespaces.  [Jeremy Kemper] 
    24 
    35* render :partial recognizes Active Record associations as Arrays.  #8538 [kamal] 
  • trunk/actionpack/lib/action_controller/resources.rb

    r6865 r6922  
    5050 
    5151      def initialize(entities, options) 
    52         @plural   = entities 
    53         @singular = options[:singular] || plural.to_s.singularize 
     52        @plural   ||= entities 
     53        @singular ||= options[:singular] || plural.to_s.singularize 
    5454 
    5555        @options = options 
     
    123123    class SingletonResource < Resource #:nodoc: 
    124124      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 
    130128      end 
    131129 
  • trunk/actionpack/test/controller/resources_test.rb

    r6862 r6922  
    1111class CommentsController < ResourcesController; end 
    1212class AuthorsController < ResourcesController; end 
    13 class LogoController < ResourcesController; end 
    14  
    15 class AccountController <  ResourcesController; end 
     13class LogosController < ResourcesController; end 
     14 
     15class AccountsController <  ResourcesController; end 
    1616class AdminController   <  ResourcesController; end 
    1717 
     
    1919  class ProductsController < ResourcesController; end 
    2020  class TagsController < ResourcesController; end 
    21   class ManufacturerController < ResourcesController; end 
     21  class ManufacturersController < ResourcesController; end 
    2222 
    2323  module Admin 
     
    264264 
    265265  def test_should_create_multiple_singleton_resource_routes 
    266     with_singleton_resources :account, :admin do 
     266    with_singleton_resources :account, :logo do 
    267267      assert_singleton_restful_for :account 
    268       assert_singleton_restful_for :admin 
     268      assert_singleton_restful_for :logo 
    269269    end 
    270270  end 
     
    273273    with_routing do |set| 
    274274      set.draw do |map| 
    275         map.resource :admin do |admin| 
     275        map.resource :admin, :controller => 'admin' do |admin| 
    276276          admin.resource :account 
    277277        end 
    278278      end 
    279279 
    280       assert_singleton_restful_for :admin 
     280      assert_singleton_restful_for :admin, :controller => 'admin' 
    281281      assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => 'admin/' 
    282282    end 
     
    370370      set.draw do |map| 
    371371        map.resources :threads do |thread| 
    372           thread.resource :admin 
     372          thread.resource :admin, :controller => 'admin' 
    373373        end 
    374374      end 
    375375 
    376376      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' } 
    378378    end 
    379379  end 
     
    429429 
    430430      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' } 
    432432    end 
    433433  end 
     
    556556    def assert_singleton_routes_for(singleton_name, options = {}) 
    557557      options[:options] ||= {} 
    558       options[:options][:controller] = options[:controller] || singleton_name.to_s 
     558      options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize 
    559559 
    560560      full_path           = "/#{options[:path_prefix]}#{singleton_name}" 
     
    590590 
    591591    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 
    593593      @controller = "#{options[:options][:controller].camelize}Controller".constantize.new 
    594594      @request    = ActionController::TestRequest.new