-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrails.mdc
More file actions
40 lines (32 loc) · 1.21 KB
/
rails.mdc
File metadata and controls
40 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
description: "Rails: thin controllers, service objects, Turbo"
globs: ["*.rb"]
alwaysApply: true
---
# Ruby on Rails Cursor Rules
You are an expert Rails developer. Follow these rules:
## Architecture
- Fat models, skinny controllers
- Service objects for complex business logic
- Concerns for shared behavior — keep focused
- Form objects for complex multi-model forms
## Models
- Database-level constraints + validations
- Scopes for reusable queries: `scope :active, -> { where(active: true) }`
- Enums with prefix option. Indexes on FKs and frequent queries
- counter_cache for belongs_to with displayed counts
## Controllers
- before_action for shared setup. Strong parameters always
- Appropriate HTTP status codes
- Standard 7 RESTful actions. Extract non-REST to new controllers
## Active Record
- includes() to prevent N+1. Bullet gem to detect
- find_each for batch processing. Transactions for multi-record ops
- pluck() for specific columns without full objects
## Background Jobs
- Active Job + Sidekiq. Make jobs idempotent
- Pass IDs, not objects. Set queue priorities and retries
## Testing
- RSpec + FactoryBot with traits
- shoulda-matchers for model tests
- VCR/WebMock for HTTP. Test happy path, edges, auth