Pakyow.orgv0.11

Namespacing Routes

Namespaces make it possible to group routes under a common URI.

namespace 'foo' do
  default do
    p 'foo: default'
  end

  get 'bar' do
    p 'foo: bar'
  end
end

# sending a GET request to '/foo' prints 'foo: default'
# sending a GET request to '/foo/bar' prints 'foo: bar'
#
# sending a GET request to '/' or '/bar' results in a 404

A namespace is implemented as a special kind of group, so everything about a group is also true of a namespace. This means that namespaces can be assigned hooks and given a name.

namespace :foo, 'foo', before: [:some_hook] do
  # foo routes go here
end
Google+