Overview
TheFormTemplate model represents a PDF form template that can be used for inspections. It stores the original PDF file, its structure, and manages relationships with inspections and form fills.
Database Schema
Attributes
Primary key
Name of the form template
Original filename of the uploaded PDF
Legacy file path (deprecated - use
original_file attachment instead)Type of the form file (e.g., “PDF”)
JSON structure defining the form fields and their properties
System category for the form template (e.g., “Fire Protection”, “Sprinkler”)
Timestamp when the template was created
Timestamp when the template was last updated
Associations
Has Many
Inspections using this templateDependent:
restrict_with_error - Cannot delete template if inspections existForm fills based on this templateDependent:
destroy - Deletes all form fills when template is deletedHas One Attached
The original PDF file uploaded for this templateValidation: Must be present
Has and Belongs to Many
Interval categories associated with this template (e.g., monthly, quarterly, annual)
Validations
name, file_type, and form_structure are commented out in the source but may be enforced at the application level.
Callbacks
Before Update
Automatically updates the This ensures all existing form fills stay synchronized with template updates.
form_structure of all associated form fills when the template’s structure changes.Trigger: When form_structure is modifiedImplementation:Public Methods
file_path
Returns the URL path for the attached original file.Returns: Implementation:
String or nilExample:Usage Examples
Creating a New Template
Updating Template Structure
Accessing Related Records
Related Models
- FormFill - Individual form instances based on this template
- Inspection - Inspections using this template