.claude/skills/active-storage-setup/SKILL.md
Configures Active Storage for file uploads with variants and direct uploads. Use when adding file uploads, image attachments, document storage, generating thumbnails, or when user mentions Active Storage, file upload, attachments, or image processing. WHEN NOT: Storing data in database columns, external URL references, static assets in the asset pipeline, or simple text/JSON storage.
npx skillsauth add ThibautBaissac/rails_ai_agents active-storage-setupInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Active Storage handles file uploads in Rails:
# Install Active Storage (if not already)
bin/rails active_storage:install
bin/rails db:migrate
# Add image processing
bundle add image_processing
# config/storage.yml
local:
service: Disk
root: <%= Rails.root.join("storage") %>
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
amazon:
service: S3
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
region: eu-west-1
bucket: <%= Rails.application.credentials.dig(:aws, :bucket) %>
google:
service: GCS
credentials: <%= Rails.root.join("config/gcs-credentials.json") %>
project: my-project
bucket: my-bucket
# config/environments/development.rb
config.active_storage.service = :local
# config/environments/production.rb
config.active_storage.service = :amazon
# app/models/user.rb
class User < ApplicationRecord
has_one_attached :avatar
# With variant defaults
has_one_attached :avatar do |attachable|
attachable.variant :thumb, resize_to_limit: [100, 100]
attachable.variant :medium, resize_to_limit: [300, 300]
end
end
# app/models/event.rb
class Event < ApplicationRecord
has_many_attached :photos
has_many_attached :documents do |attachable|
attachable.variant :preview, resize_to_limit: [200, 200]
end
end
Active Storage Progress:
- [ ] Step 1: Add attachment to model
- [ ] Step 2: Write model spec for attachment
- [ ] Step 3: Add validations (type, size)
- [ ] Step 4: Create upload form
- [ ] Step 5: Handle in controller
- [ ] Step 6: Display in views
- [ ] Step 7: Test upload flow
See testing.md for model specs, factory traits, and request specs.
Key patterns:
fixture_file_upload in request specs:with_avatar factory traits using after(:build)be_attached and variant presence in model specsUse the active_storage_validations gem for declarative validation, or write manual validate methods. See validations.md for both approaches.
# Gemfile
gem 'active_storage_validations'
Define named variants on the model attachment using resize_to_fill, resize_to_limit, or resize_to_cover. See variants-and-views.md for variant operations, view helpers, and form examples.
:avatar for single uploads, photos: [] for multiplepurge to remove attachments, with optional Turbo Stream responserails_blob_path or send_data for downloadsSee controller-and-service.md for full controller examples, service methods, direct uploads setup, and performance tips.
development
Creates Turbo Streams, Turbo Frames, and morphing patterns for real-time UI updates. Use when adding real-time updates, partial page rendering, form submissions, or broadcasting. WHEN NOT: For Stimulus JavaScript controllers (see stimulus-patterns skill). For general view conventions (see rules/views.md).
testing
Writes Minitest tests with fixtures following 37signals conventions. Uses Minitest (not RSpec) and fixtures (not factories). Use when writing tests, adding test coverage, or creating fixtures. WHEN NOT: For RSpec or FactoryBot patterns (this project uses Minitest + fixtures exclusively). For test configuration/CI setup (see project docs).
tools
Builds focused, single-purpose Stimulus controllers for progressive enhancement. Use when adding JavaScript behavior, UI interactions, form enhancements, or building reusable client-side components. WHEN NOT: For Turbo Stream/Frame patterns (see turbo-patterns skill). For server-side view logic (see rules/views.md).
testing
Implements the state-as-records-not-booleans pattern for rich state tracking. Use when modeling state changes, replacing boolean flags with record-based state, or when user mentions state records, closures, publications, or toggling state. WHEN NOT: Technical flags like cached/processed (use booleans), concern extraction (use concern-patterns), general model work (use model-patterns).