active-storage-setup
Skill665 starsChanged 6 months agoMITView on GitHub
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.
- Reads credentials
In this repository43 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude_37signals/CLAUDE.mdCLAUDE.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- accessibility-reviewSkill
- action-cable-patternsSkill
- api-versioningSkill
- authentication-flowSkill
- behavioral-guidelinesSkill
- caching-strategiesSkill
- code-reviewSkill
- codex-reviewSkill
- dependabot-reviewSkill
- extraction-timingSkill
- friction-reviewSkill
- i18n-patternsSkill
- mutation-testingSkill
- performance-optimizationSkill
- postgres-patternsSkill
- rails-architectureSkill
- rails-concernSkill
- security-auditSkill
- solid-queue-setupSkill
- accessibility-reviewSkill
- action-cable-patternsSkill
- active-storage-setupSkill
- api-versioningSkill
- authentication-flowSkill
- behavioral-guidelinesSkill
- caching-strategiesSkill
- code-reviewSkill
- codex-reviewSkill
- dependabot-reviewSkill
- extraction-timingSkill
- friction-reviewSkill
- i18n-patternsSkill
- mutation-testingSkill
- performance-optimizationSkill
- postgres-patternsSkill
- rails-architectureSkill
- rails-concernSkill
- security-auditSkill
- solid-queue-setupSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 119
Use fixture_file_upload in request specs
- Very specific: line 121
Test be_attached and variant presence in model specs
- Very specific: line 125
Use the active_storage_validations gem for declarative validation, or write manual validate methods.
- Very specific: line 139
Use purge to remove attachments, with optional Turbo Stream response
- Very specific: line 140
Use rails_blob_path or send_data for downloads
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Active Storage Setup for Rails 8
Overview
Active Storage handles file uploads in Rails:
- Cloud storage (S3, GCS, Azure) or local disk
- Image variants (thumbnails, resizing)
- Direct uploads from browser
- Polymorphic attachments
Quick Start
# Install Active Storage (if not already)
bin/rails active_storage:install
bin/rails db:migrate
# Add image processing
bundle add image_processingConfiguration
Storage Services
# 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-bucketEnvironment Config
# config/environments/development.rb
config.active_storage.service = :local
# config/environments/production.rb
config.active_storage.service = :amazonModel Attachments
Single Attachment
# 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
endMultiple Attachments
# 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
endTDD Workflow
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 flowTesting Attachments
See testing.md for model specs, factory traits, and request specs.
Key patterns:
- Use
fixture_file_uploadin request specs - Define
:with_avatarfactory traits usingafter(:build) - Test
be_attachedand variant presence in model specs
Validations
Use the active_storage_validations gem for declarative validation, or write manual validate methods. See validations.md for both approaches.
# Gemfile
gem 'active_storage_validations'Image Variants
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.
Controller and Service Handling
- Permit
:avatarfor single uploads,photos: []for multiple - Use
purgeto remove attachments, with optional Turbo Stream response - Use
rails_blob_pathorsend_datafor downloads
See controller-and-service.md for full controller examples, service methods, direct uploads setup, and performance tips.
Checklist
- Active Storage installed and migrated
- Storage service configured
- Image processing gem added (if using variants)
- Attachment added to model
- Validations added (type, size)
- Variants defined
- Controller permits attachment params
- Form handles file upload
- Tests written for attachments
- Direct uploads configured (if needed)
References
- testing.md - Model specs, factory traits, request specs
- validations.md - Gem-based and manual validation examples
- variants-and-views.md - Variant definitions, view helpers, upload forms
- controller-and-service.md - Controllers, service methods, direct uploads, performance
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

