Agent skill
resource
Overview of Plutonium resources - what they are and how the pieces fit together
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/resource-radioactive-labs-plutonium-core
SKILL.md
Plutonium Resources
A resource in Plutonium is the combination of four layers that work together to provide full CRUD functionality with minimal code.
The Four Layers
| Layer | File | Purpose |
|---|---|---|
| Model | app/models/post.rb |
Data, validations, associations, business rules |
| Definition | app/definitions/post_definition.rb |
UI configuration - how fields render, actions, filters |
| Policy | app/policies/post_policy.rb |
Authorization - who can do what |
| Controller | app/controllers/posts_controller.rb |
Request handling - usually empty, inherits CRUD |
┌─────────────────────────────────────────────────────────────────┐
│ Resource │
├─────────────────────────────────────────────────────────────────┤
│ Model │ Definition │ Policy │ Controller │
│ (WHAT it is) │ (HOW it looks) │ (WHO can act) │ (HOW it │
│ │ │ │ responds) │
├─────────────────────────────────────────────────────────────────┤
│ - attributes │ - field types │ - permissions │ - CRUD │
│ - associations │ - inputs/forms │ - scoping │ - redirects│
│ - validations │ - displays │ - attributes │ - params │
│ - scopes │ - actions │ │ │
│ - callbacks │ - filters │ │ │
└─────────────────────────────────────────────────────────────────┘
Creating Resources
New Resources (from scratch)
Use the scaffold generator to create all four layers at once:
rails g pu:res:scaffold Post title:string content:text:required published:boolean
This generates:
app/models/post.rb- Model with validationsapp/definitions/post_definition.rb- Definition (empty, uses auto-detection)app/policies/post_policy.rb- Policy with sensible defaultsapp/controllers/posts_controller.rb- Controller (empty, inherits CRUD)- Migration file
See create-resource skill for full generator options.
From Existing Models
For existing Rails projects, you can convert models to Plutonium resources:
- Include the module in your model:
class Post < ApplicationRecord
include Plutonium::Resource::Record
# Your existing code...
end
Or inherit from a base class that includes it:
class Post < ResourceRecord
# Your existing code...
end
- Generate the supporting files (definition, policy, controller):
rails g pu:res:scaffold Post --no-migration
This creates definition, policy, and controller without touching your existing model.
- Connect to a portal:
rails g pu:res:conn Post --dest=admin_portal
Connecting to Portals
Resources must be connected to a portal to be accessible:
rails g pu:res:conn Post --dest=admin_portal
This:
- Registers the resource in portal routes
- Creates portal-specific controller
- Creates portal-specific policy with attribute permissions
See connect-resource skill for details.
Layer Responsibilities
Model (Data Layer)
class Post < ResourceRecord
belongs_to :author, class_name: "User"
has_many :comments
validates :title, presence: true
scope :published, -> { where(published: true) }
end
The model handles:
- Database schema and associations
- Data validation
- Business logic scopes
- Callbacks
Skills: model, model-features
Definition (UI Layer)
class PostDefinition < ResourceDefinition
# Override auto-detected field types
input :content, as: :rich_text
# Add filters and scopes
filter :published, with: Plutonium::Query::Filters::Boolean
scope :published
# Add actions
action :publish, interaction: PublishPostInteraction
end
The definition handles:
- Field type overrides (auto-detection handles most cases)
- Form input customization
- Display formatting
- Search, filters, scopes, sorting
- Actions (interactive operations)
Skills: definition, definition-fields, definition-actions, definition-query
Policy (Authorization Layer)
class PostPolicy < ResourcePolicy
# Who can perform actions
def create?
user.present?
end
def read?
true
end
def publish?
user.admin? || record.author == user
end
# What records are visible
relation_scope do |relation|
return relation if user.admin?
relation.where(author: user)
end
# What attributes are readable/writable
def permitted_attributes_for_read
%i[title content published author created_at]
end
def permitted_attributes_for_create
%i[title content]
end
end
The policy handles:
- Action authorization (create?, update?, destroy?, custom actions)
- Resource scoping (what records user can see)
- Attribute permissions (read/write access per field)
Skill: policy
Controller (Request Layer)
class PostsController < ::ResourceController
# Empty - all CRUD actions inherited automatically
end
Controllers are usually empty because they inherit full CRUD functionality. Customize only when needed:
class PostsController < ::ResourceController
private
def preferred_action_after_submit
"index" # Redirect to list instead of show
end
end
The controller handles:
- Request/response cycle
- Redirect logic
- Custom parameter processing
- Non-standard authorization flows
Skill: controller
Auto-Detection
Plutonium automatically detects from your model:
- All database columns with appropriate field types
- Associations (belongs_to, has_one, has_many)
- Attachments (Active Storage)
- Enums
You only need to declare when overriding defaults.
Portal-Specific Customization
Each portal can have its own definition that overrides the base:
# Base definition
class PostDefinition < ResourceDefinition
scope :published
end
# Admin portal sees more
class AdminPortal::PostDefinition < ::PostDefinition
scope :draft
scope :pending_review
action :feature, interaction: FeaturePostInteraction
end
# Public portal is restricted
class PublicPortal::PostDefinition < ::PostDefinition
# Only published scope, no actions
end
Workflow Summary
- Generate -
rails g pu:res:scaffold Model attributes... --dest=main_app - Connect -
rails g pu:res:conn Model --dest=portal_name - Customize - Edit definition/policy as needed (model rarely needs changes)
- Override per portal - Create portal-specific definitions when needed
Related Skills
model- Model structure and organizationmodel-features- has_cents, associations, scopes, routesdefinition- Definition overview and structuredefinition-fields- Fields, inputs, displays, columnsdefinition-actions- Actions and interactionsinteraction- Writing interaction classesdefinition-query- Search, filters, scopes, sortingpolicy- Authorization and permissionscontroller- Controller customizationviews- Custom pages, displays, tables using Phlexforms- Custom form templates and field buildersassets- TailwindCSS and component themingpackage- Feature and portal packagesportal- Portal configuration and entity scopingnested-resources- Parent/child routes and scopinginstallation- Setting up Plutoniumrodauth- Authentication setupcreate-resource- Scaffold generator detailsconnect-resource- Portal connection details
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?