Skip to content

/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_to via source_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.destinations or source_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
  • 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_to via destination_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.sources or destination_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
  • 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_to via host_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
  • Related Documentation: Domains

Reverse Associations

The following resources connect to Resource:

Resource[] (Destinations)
  • Type: has_many on Resource via source_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
  • 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_many on Resource via destination_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
  • 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 filtering
  • scope=name - Apply named scope (e.g., sourceable, usable, sourced, used)
  • page=N - Page number for pagination
  • per_page=N - Items per page (default: 25)

Request Examples:

bash
curl -X GET "https://your-company.erpax.com/admin/resources.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"
bash
curl -X GET "https://your-company.erpax.com/admin/resources.json?scope=sourceable" \
  -H "Accept: application/json"

JavaScript Example:

javascript
const response = await fetch('/admin/resources.json', {
  credentials: 'include',
  headers: { 'Accept': 'application/json' }
});
const data = await response.json();

Response (200 OK):

json
{
  "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:

bash
curl -X GET "https://your-company.erpax.com/admin/resources/1.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"

JavaScript Example:

javascript
const response = await fetch('/admin/resources/1.json', {
  credentials: 'include',
  headers: { 'Accept': 'application/json' }
});
const data = await response.json();

Response (200 OK):

json
{
  "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:

bash
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:

javascript
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):

json
{
  "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:

bash
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:

javascript
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):

json
{
  "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:

bash
curl -X DELETE "https://your-company.erpax.com/admin/resources/1.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"

JavaScript Example:

javascript
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:

bash
GET /admin/resources.json?scope=sourceable
GET /admin/resources.json?scope=usable

Filters

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

Released under an open source license.