Back to list
radioactive-labs

plutonium-create-resource

by radioactive-labs

Build production-ready Rails apps in minutes, not days. Convention-driven, fully customizable, AI-ready.

52🍴 7📅 Jan 23, 2026

SKILL.md


name: plutonium-create-resource description: Generate Plutonium resources with models, migrations, controllers, policies, and definitions

Create Resource Skill

Use the pu:res:scaffold generator to create complete resources in Plutonium applications.

Command Syntax

rails g pu:res:scaffold MODEL_NAME \
    field1:type \
    field2:type \
    --dest=DESTINATION

IMPORTANT: Always specify --dest to avoid interactive prompts:

  • --dest=main_app for resources in the main application
  • --dest=package_name for resources in a feature package

IMPORTANT: Quote fields containing ? or {} to prevent shell expansion:

'field:type?'              # Nullable - must quote
'field:decimal{10,2}'      # Options - must quote
'field:decimal?{10,2}'     # Both - must quote

From Existing Models

For existing Rails projects with models you want to convert to Plutonium resources:

Option 1: Model already includes Plutonium::Resource::Record

rails g pu:res:scaffold Post --no-migration --dest=main_app

This generates only the definition, policy, and controller - leaving your model unchanged.

Option 2: Let the generator update the model

rails g pu:res:scaffold Post --dest=main_app

Run without attributes to auto-import fields from model.content_columns. This regenerates the model file, so review changes carefully.

Don't forget to include the module

Your model must include Plutonium::Resource::Record (directly or via inheritance):

class Post < ApplicationRecord
  include Plutonium::Resource::Record
end

# Or inherit from a base class
class Post < ResourceRecord
end

Field Type Syntax

Format: name:type:index_type

Basic Types

SyntaxResult
name:stringRequired string
'name:string?'Nullable string
age:integerRequired integer
'age:integer?'Nullable integer
active:booleanRequired boolean
'active:boolean?'Nullable boolean
content:textRequired text
'content:text?'Nullable text
birth_date:dateRequired date
'anniversary:date?'Nullable date
starts_at:datetimeRequired datetime
'ends_at:datetime?'Nullable datetime
alarm_time:timeRequired time
'reminder_time:time?'Nullable time

Decimal with Precision

The {precision,scale} syntax only works for decimal types:

'latitude:decimal{11,8}'           # precision: 11, scale: 8
'amount:decimal{10,2}'             # precision: 10, scale: 2
'latitude:decimal?{11,8}'          # nullable with precision

Note: For default values on other types (boolean, integer, etc.), edit the migration manually.

References/Associations

company:belongs_to                 # Required foreign key
'parent:belongs_to?'               # Nullable (null: true + optional: true)
user:references                    # Same as belongs_to
blogging/post:belongs_to           # Cross-package reference

Nullable references generate:

  • Migration: null: true
  • Model: belongs_to :parent, optional: true

Index Types (third segment)

email:string:index                 # Regular index
email:string:uniq                  # Unique index

Special Types

password_digest                    # has_secure_password
auth_token:token                   # has_secure_token (auto unique index)
content:rich_text                  # has_rich_text
avatar:attachment                  # has_one_attached
photos:attachments                 # has_many_attached
price_cents:integer                # has_cents (money field)

Token fields automatically get a unique index in the migration.

Generator Options

  • --dest=DESTINATION - Target destination (always required to avoid prompts)
    • main_app for main application resources
    • package_name for feature package resources
  • --no-model - Skip model generation (keeps existing model)
  • --no-migration - Skip migration generation (use with --no-model for existing models)

What Gets Generated

For main_app resources:

  1. Model - app/models/model_name.rb
  2. Migration - db/migrate/xxx_create_model_names.rb
  3. Controller - app/controllers/model_names_controller.rb
  4. Policy - app/policies/model_name_policy.rb
  5. Definition - app/definitions/model_name_definition.rb

For packaged resources:

  1. Model - app/models/package_name/model_name.rb
  2. Migration - db/migrate/xxx_create_package_name_model_names.rb
  3. Controller - packages/package_name/app/controllers/package_name/model_names_controller.rb
  4. Policy - packages/package_name/app/policies/package_name/model_name_policy.rb
  5. Definition - packages/package_name/app/definitions/package_name/model_name_definition.rb

Migration Customizations

The generator creates basic migrations. Always review and customize the migration before running:

Inline Indexes (preferred)

create_table :model_names do |t|
  t.belongs_to :parent, null: false, foreign_key: true
  t.string :name, null: false

  t.timestamps

  t.index :name
  t.index [:parent_id, :name], unique: true
end

Cascade Delete

t.belongs_to :parent, null: false, foreign_key: {on_delete: :cascade}

Default Values

t.boolean :is_active, default: true
t.integer :status, default: 0
t.integer :count, null: true, default: 0

Examples

Main App Resource

rails g pu:res:scaffold Post \
    user:belongs_to \
    title:string \
    'content:text?' \
    'published_at:datetime?' \
    --dest=main_app

Resource with Precision and Indexes

rails g pu:res:scaffold Property \
    company:belongs_to \
    code:string:uniq \
    'latitude:decimal{11,8}' \
    'longitude:decimal?{11,8}' \
    'value:decimal?{15,2}' \
    'notes:text?' \
    --dest=main_app

Optional Association

rails g pu:res:scaffold Comment \
    user:belongs_to \
    'parent:belongs_to?' \
    body:text \
    --dest=blogging

Cross-Package Reference

rails g pu:res:scaffold Comment \
    user:belongs_to \
    blogging/post:belongs_to \
    body:text \
    --dest=comments

After Generation

  1. Review and customize the migration (add cascade delete, defaults, composite indexes)
  2. Run rails db:migrate
  3. Connect resource to portal: rails g pu:res:conn Post --dest=admin_portal
  4. Customize policy permissions as needed
  5. Add definition customizations for UI behavior

Score

Total Score

75/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon