/admin/resources
Path: /admin/resources
Namespace: admin
Resource: resources
Overview
The Resource resource represents inventory resources with source and destination tracking. Resources track quantity, unit quantity, and status for inventory management.
Relationships
Model Associations
Resource connects to the following resources:
Resource (Source)
- Type:
belongs_toviasource_id(self-referential, optional) - Field:
source_id - Description: Source resource from which this resource originates. Resources can have source/destination relationships for inventory tracking and transfers.
- Reverse: Resource has many destination resources (
resource.destinationsorsource_resource.destinations) - API Access:
- Direct: Included in resource response as
source_id(may be null) - Filter:
GET /admin/resources.json?q[source_id_eq]=123
- Direct: Included in resource response as
- Example: Get all resources sourced from a specific resource:javascript
const sourcedResources = await fetch('/admin/resources.json?q[source_id_eq]=123', { credentials: 'include', headers: { 'Accept': 'application/json' } }).then(r => r.json());
Resource (Destination)
- Type:
belongs_toviadestination_id(self-referential, optional) - Field:
destination_id - Description: Destination resource to which this resource is allocated. Resources can track where inventory is allocated or transferred.
- Reverse: Resource has many source resources (
resource.sourcesordestination_resource.sources) - API Access:
- Direct: Included in resource response as
destination_id(may be null) - Filter:
GET /admin/resources.json?q[destination_id_eq]=123
- Direct: Included in resource response as
- Example: Get all resources allocated to a specific destination:javascript
const allocatedResources = await fetch('/admin/resources.json?q[destination_id_eq]=123', { credentials: 'include', headers: { 'Accept': 'application/json' } }).then(r => r.json());
Domain
- Type:
belongs_toviahost_id - Field:
host_id - Description: Tenant domain for multi-tenant scoping. All resources belong to a domain.
- Reverse: Domain has many resources (
domain.resources) - API Access:
- Direct: Included in resource response as
host_id - Filter:
GET /admin/resources.json?q[host_id_eq]=1
- Direct: Included in resource response as
- Related Documentation: Domains
Reverse Associations
The following resources connect to Resource:
Resource[] (Destinations)
- Type:
has_manyon Resource viasource_id(self-referential) - Description: Resources that are sourced from this resource. Track all downstream allocations.
- API Access:
- Filter:
GET /admin/resources.json?q[source_id_eq]=123
- Filter:
- Example: Get all resources sourced from this resource:javascript
const destinations = await fetch('/admin/resources.json?q[source_id_eq]=123', { credentials: 'include', headers: { 'Accept': 'application/json' } }).then(r => r.json());
Resource[] (Sources)
- Type:
has_manyon Resource viadestination_id(self-referential) - Description: Resources that are allocated to this resource. Track all upstream sources.
- API Access:
- Filter:
GET /admin/resources.json?q[destination_id_eq]=123
- Filter:
- Example: Get all resources allocated to this resource:javascript
const sources = await fetch('/admin/resources.json?q[destination_id_eq]=123', { credentials: 'include', headers: { 'Accept': 'application/json' } }).then(r => r.json());
Relationship Patterns
Resource Chain Tracking
- Use Case: Track inventory flow from source to destination
- Example: Get complete resource chain:javascript
// Get source resource const source = await fetch('/admin/resources/1.json', { credentials: 'include', headers: { 'Accept': 'application/json' } }).then(r => r.json()); // Get all destinations const destinations = await fetch('/admin/resources.json?q[source_id_eq]=1', { credentials: 'include', headers: { 'Accept': 'application/json' } }).then(r => r.json());
Creating Resource with Source/Destination
- Use Case: Create a resource with source and destination relationships
- Example:javascript
const resource = await fetch('/admin/resources.json', { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify({ resource: { source_id: 10, destination_id: 20, quantity: 100, unit_quantity: 10, status: 'active' } }) }).then(r => r.json());
Filtering by Status
- Use Case: Get active resources for a specific source
- Example:javascript
const activeResources = await fetch('/admin/resources.json?q[source_id_eq]=123&q[status_eq]=active', { credentials: 'include', headers: { 'Accept': 'application/json' } }).then(r => r.json());
Key Features
- Source/Destination Tracking: Resources have source and destination associations
- Quantity Management: Track quantity and unit_quantity
- Status Tracking: Resource status management
- Inventory Management: Support for inventory tracking and management
Available Operations
List Resources (GET)
Endpoint: GET /admin/resources.json
Query Parameters:
q[field_predicate]=value- Ransack query filters for advanced filteringscope=name- Apply named scope (e.g.,sourceable,usable,sourced,used)page=N- Page number for paginationper_page=N- Items per page (default: 25)
Request Examples:
curl -X GET "https://your-company.erpax.com/admin/resources.json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie"curl -X GET "https://your-company.erpax.com/admin/resources.json?scope=sourceable" \
-H "Accept: application/json"JavaScript Example:
const response = await fetch('/admin/resources.json', {
credentials: 'include',
headers: { 'Accept': 'application/json' }
});
const data = await response.json();Response (200 OK):
{
"resources": [
{
"id": 1,
"source_id": 10,
"destination_id": 20,
"quantity": 100,
"unit_quantity": 10,
"status": "active",
"created_at": "2024-01-15T10:00:00Z"
}
],
"meta": {
"current_page": 1,
"per_page": 25,
"total_pages": 1,
"total_count": 5
}
}Show Resource (GET /:id)
Endpoint: GET /admin/resources/:id.json
Request Example:
curl -X GET "https://your-company.erpax.com/admin/resources/1.json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie"JavaScript Example:
const response = await fetch('/admin/resources/1.json', {
credentials: 'include',
headers: { 'Accept': 'application/json' }
});
const data = await response.json();Response (200 OK):
{
"resource": {
"id": 1,
"source_id": 10,
"destination_id": 20,
"quantity": 100,
"unit_quantity": 10,
"status": "active",
"created_at": "2024-01-15T10:00:00Z",
"updated_at": "2024-01-15T12:00:00Z"
}
}Create Resource (POST)
Endpoint: POST /admin/resources.json
Note: Create actions may be restricted for resources. Only index, show, edit, and update actions are typically enabled.
Request Example:
curl -X POST "https://your-company.erpax.com/admin/resources.json" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie" \
-d '{
"resource": {
"source_id": 10,
"destination_id": 20,
"quantity": 100,
"unit_quantity": 10,
"status": "active"
}
}'JavaScript Example:
const response = await fetch('/admin/resources.json', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
resource: {
source_id: 10,
destination_id: 20,
quantity: 100,
unit_quantity: 10,
status: 'active'
}
})
});
const data = await response.json();Response (201 Created):
{
"resource": {
"id": 2,
"source_id": 10,
"destination_id": 20,
"quantity": 100,
"unit_quantity": 10,
"status": "active",
"created_at": "2024-01-15T14:30:00Z"
}
}Update Resource (PATCH /:id)
Endpoint: PATCH /admin/resources/:id.json
Request Example:
curl -X PATCH "https://your-company.erpax.com/admin/resources/1.json" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie" \
-d '{
"resource": {
"quantity": 150,
"status": "inactive"
}
}'JavaScript Example:
const response = await fetch('/admin/resources/1.json', {
method: 'PATCH',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
resource: {
quantity: 150,
status: 'inactive'
}
})
});
const data = await response.json();Response (200 OK):
{
"resource": {
"id": 1,
"quantity": 150,
"status": "inactive",
"updated_at": "2024-01-15T15:00:00Z"
}
}Delete Resource (DELETE /:id)
Endpoint: DELETE /admin/resources/:id.json
Note: Delete actions may be restricted for resources. Only index, show, edit, and update actions are typically enabled.
Request Example:
curl -X DELETE "https://your-company.erpax.com/admin/resources/1.json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie"JavaScript Example:
const response = await fetch('/admin/resources/1.json', {
method: 'DELETE',
credentials: 'include',
headers: { 'Accept': 'application/json' }
});Response (204 No Content):
(empty response)Scopes
- all (default) - All resources
- sourceable - Resources that can be used as sources
- usable - Resources that can be used
- sourced - Resources that have been sourced
- used - Resources that have been used
Usage Example:
GET /admin/resources.json?scope=sourceable
GET /admin/resources.json?scope=usableFilters
Available filters for searching and filtering resources:
- id - Filter by resource ID
- source_code_or_destination_code_cont - Text filter - Search by source or destination code (contains)
- source_name_or_destination_name_cont - Text filter - Search by source or destination name (contains)
- quantity - Numeric filter - Filter by quantity
- unit_quantity - Numeric filter - Filter by unit quantity
- created_at - Date filter - Filter by creation date
- updated_at - Date filter - Filter by update date
Business Rules
- Source/Destination Association: Resources can have source and destination associations
- Quantity Management: Quantity and unit_quantity track resource amounts
- Status Management: Resources have status for tracking availability
- Domain Scoping: Resources are automatically scoped to the current domain
Related Resources
- Items - Items may be associated with resources
- Item Transfers - Item transfer operations