Naming Conventions
Wallaby relies on Rails-style naming conventions to connect a model with everything else: controllers, decorators, servicers, authorizers and paginators.
For a model class e.g. Product:
| Purpose | Class Name | Location |
|---|---|---|
| Controller | ProductsController / Admin::ProductsController | app/controllers/ |
| Decorator | ProductDecorator | app/decorators/ |
| Servicer | ProductServicer | app/servicers/ |
| Authorizer | ProductAuthorizer | app/authorizers/ |
| Paginator | ProductPaginator | app/paginators/ |
Decorator
See Decorator for how to create and customize decorators.
For model Product, the decorator should be named ProductDecorator:
# app/decorators/product_decorator.rb
class ProductDecorator < Admin::ApplicationDecorator
end
When a model is namespaced e.g. Order::Item, the decorator can be placed under the same namespace as either:
# app/decorators/admin/order/item_decorator.rb
class Admin::Order::ItemDecorator < Admin::ApplicationDecorator
end
# or
# app/decorators/order/item_decorator.rb
class Order::ItemDecorator < Admin::ApplicationDecorator
end
Wallaby tries the demodulized variants (Admin::Order::ItemDecorator, Order::ItemDecorator, ItemDecorator) until it finds a constantized class.
If the name cannot reflect the association, .model_class can be set to specify the model class explicitly.
Servicer
See Servicer for how to create and customize servicers.
For model Product, the servicer should be named ProductServicer:
# app/servicers/product_servicer.rb
class ProductServicer < Admin::ApplicationServicer
end
The same demodulized lookup applies to servicers (e.g. Admin::Order::ItemServicer).
Authorizer
See Authorizer for how to create and customize authorizers.
For model Product, the authorizer should be named ProductAuthorizer:
# app/authorizers/product_authorizer.rb
class ProductAuthorizer < Admin::ApplicationAuthorizer
end
Paginator
See Paginator for how to create and customize paginators.
For model Product, the paginator should be named ProductPaginator:
# app/paginators/product_paginator.rb
class ProductPaginator < Admin::ApplicationPaginator
end
Controller
See Controller for how to create and customize controllers.
For model Product, the controller should be created under the mounted namespace (e.g. Admin) as Admin::ProductsController:
# app/controllers/admin/products_controller.rb
class Admin::ProductsController < Admin::ApplicationController
end
For a namespaced model Order::Item, the controller becomes Admin::Order::ItemsController.
If the controller name cannot reflect the association, .model_class can be set to specify the model class explicitly.
URL Naming
The URL name of a model is the pluralized, underscored (tableized) class name. Namespaces are separated by double colons:
Product->productsOrder::Item->order::items
For example, the index page of Order::Item is accessed at /admin/order::items, and the corresponding path helpers take the URL name:
wallaby_engine.resources_path('order::items') # => /admin/order::items
See Route - Path and URL Helpers for the full list of predefined route helpers.