Flowdock
method

namespace

Importance_2
v2.3.8 - Show latest stable - 1 note - Class: ActionController::Routing::RouteSet::Mapper
namespace(name, options = {}, &block) public

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.

Show source
Register or log in to add new notes.
May 27, 2010
2 thanks

Use :path_prefix for the namespace

Resources are added after the :path_prefix. However if you use a :path_prefix on a resource, it overrides the namespace path instead of appending to it (as I think it should).

Here is what I wrote to create a versioned API access path.

map.namespace :api3, :path_prefix=>"/api/v3" do |api|
  api.resources :posts
  api.resources :comments, :path_prefix=>"/api/v3/post/:post_id"
end

This will create routes like

path: /api/v3/posts/1 
named_route: api3_post()
controller=>"api3/posts"