diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-27 16:58:36 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-27 16:58:36 +0000 |
commit | 8326a15784550f8a909e140f828dc0b1c83d617c (patch) | |
tree | 7c57a4c50944c6a2df6a5af63e2dd11a0fd2215b /actionpack/lib | |
parent | f985bfd8f8854a3d27da39237ce410d12955595a (diff) | |
download | rails-8326a15784550f8a909e140f828dc0b1c83d617c.tar.gz rails-8326a15784550f8a909e140f828dc0b1c83d617c.tar.bz2 rails-8326a15784550f8a909e140f828dc0b1c83d617c.zip |
Added map.namespace to deal with the common situation of admin sections and the like [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6594 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/resources.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 63f2b67755..6a2280a6d3 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -18,7 +18,7 @@ module ActionController end def controller - @controller ||= (options[:controller] || plural).to_s + @controller ||= "#{options[:namespace]}#{(options[:controller] || plural).to_s}" end def requirements(with_id = false) @@ -301,6 +301,22 @@ module ActionController entities.each { |entity| map_singleton_resource(entity, options.dup, &block) } end + # Enables the use of resources in a module by setting the name_prefix, path_prefix, and namespace for the model. + # Example: + # + # map.namespace(:admin) do |admin| + # admin.resources :products, + # :has_many => [ :tags, :images, :variants ] + # end + # + # This will create admin_products_url pointing to "admin/products", which will look for an Admin::ProductsController. + # It'll also create admin_product_tags_url pointing to "admin/products/#{product_id}/tags", which will look for + # Admin::TagsController. + def namespace(name, options = {}, &block) + with_options({ :path_prefix => name, :name_prefix => "#{name}_", :namespace => "#{name}/" }.merge(options), &block) + end + + private def map_resource(entities, options = {}, &block) resource = Resource.new(entities, options) |