Class: Wallaby::ResourcesRouter
- Inherits:
-
Object
- Object
- Wallaby::ResourcesRouter
- Defined in:
- lib/routes/wallaby/resources_router.rb
Overview
This is the core of Wallaby as it dynamically dispatches request to appropriate controller and action.
Assume that:
-
Wallaby is mounted at ‘/admin`
-
current request path is ‘/admin/order::items`, then the resources name is `order::items`
ResourcesRouter will try to find out which controller to dispatch to by:
-
check if the controller name ‘Admin::Order::ItemsController` exists (converted from the mount path and resources name)
-
check if the ‘:resources_controller` defaults is set when mounting Wallaby, for example:
“‘ wallaby_mount at: ’/admin’, defaults: { resources_controller: CoreController } “‘
-
fall back to default resources controller from Wallaby.configuration.resources_controller
Instance Method Summary collapse
-
#call(env) ⇒ void
It dispatches the request to corresponding controller and action.
Instance Method Details
#call(env) ⇒ void
This method returns an undefined value.
It dispatches the request to corresponding controller and action.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/routes/wallaby/resources_router.rb', line 28 def call(env) = (env) validate_model_by([:resources]) controller_class = find_controller_class_by() controller_class.action([:action]).call(env) rescue ::AbstractController::ActionNotFound, ModelNotFound => e Wallaby::Logger.warn(e, sourcing: 1) default_controller().action(:not_found).call(env) rescue UnprocessableEntity => e set_flash_error_for(e, env) default_controller().action(:unprocessable_entity).call(env) end |