Rails Idioms and Patterns
Rails rewards convention over configuration, Active Record, and RESTful design. Idiomatic Rails = conventional, tested, Hotwire-aware.
Scope: Rails-specific patterns. For Ruby:
@.gemini/skills/ruby-idioms/SKILL.md.
Active Record
Scopes for reusable queries:
class Task < ApplicationRecord scope :active, -> { where(status: :active) } scope :by_priority, -> { order(priority: :desc) } endValidations in models, not controllers:
class Task < ApplicationRecord validates :title, presence: true, length: { maximum: 200 } validates :priority, inclusion: { in: %w[low medium high] } endincludes/preloadfor eager loading — avoid N+1.
Controllers
- RESTful actions — only standard 7 actions per controller. Custom actions = new controller.
- Strong parameters — never mass-assign without permit.
- Service objects for complex business logic.
Hotwire (7+)
- Turbo Frames for partial page updates.
- Turbo Streams for real-time updates.
- Stimulus for JavaScript sprinkles — minimal JS.
Testing
RSpec (preferred):
RSpec.describe TasksController, type: :request do describe 'POST /tasks' do it 'creates a task' do post tasks_path, params: { task: { title: 'Test', priority: 'high' } } expect(response).to have_http_status(:created) end end endFactoryBot for test data. Database Cleaner for isolation.
Formatting and Static Analysis
| Tool | Purpose | Command |
|---|---|---|
| RuboCop + rubocop-rails | Linting | rubocop --autocorrect |
| Brakeman | Security | brakeman --no-pager |
bundle audit |
CVE scanning | bundle audit check --update |
Related
- Ruby Idioms @.gemini/skills/ruby-idioms/SKILL.md
- Database Design Principles @.gemini/skills/database-design-principles/SKILL.md