TL; DR namespace scope
Rails.root
|
+
| |
| +
| |
| +
+
|
+
routes.rb ActionController::RoutingError: uninitialized constant Api:
namespace :api do
namespace :v1 do
resources :jobs
end
end
:
scope :api do
scope :v1 do
resources :jobs
end
end
Rails Routing from Outside In:
Namespace will automatically add the area :as, as well as :moduleand :path.
Indeed, a namespace is just a wrapper around an area with a set of predefined options:
def namespace(path, options = {})
path = path.to_s
defaults = {
module: path,
path: options.fetch(:path, path),
as: options.fetch(:as, path),
shallow_path: options.fetch(:path, path),
shallow_prefix: options.fetch(:as, path)
}
scope(defaults.merge!(options)) { yield }
end
source
share