Skip to content

Commit bd9bacc

Browse files
committed
feat: define Thoughtbot rules for AI-enabled IDEs
During a Fusion AI task force meeting, we discussed the tools we use and how we enforce rules. As part of that conversation, we decided it would be valuable to define official thoughtbot guidelines for editors that integrate AI, such as Cursor. This PR opens the discussion by proposing an initial set of rules I put together. These are meant as a starting point.
1 parent a46e47a commit bd9bacc

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

rails/ai-rules/rails-rules.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus).
2+
3+
Code Style and Structure
4+
- Follow thoughtbot's guide to write idiomatic Ruby https://github.com/thoughtbot/guides/tree/main/ruby
5+
- Follow Rails conventions and best practices.
6+
- Use object-oriented and functional programming patterns as appropriate.
7+
- Prefer iteration and modularization over code duplication.
8+
- Use descriptive variable and method names (e.g., user_signed_in?, calculate_total).
9+
- Structure files according to Rails conventions (MVC, concerns, helpers, etc.).
10+
11+
Naming Conventions
12+
- Use snake_case for file names, method names, and variables.
13+
- Use CamelCase for class and module names.
14+
- Follow Rails naming conventions for models, controllers, and views.
15+
16+
Ruby and Rails Usage
17+
- Use Ruby 3.x features when appropriate (e.g., pattern matching, endless methods).
18+
- Leverage Rails' built-in helpers and methods.
19+
- Use ActiveRecord effectively for database operations.
20+
21+
Syntax and Formatting
22+
- Follow the Ruby Style Guide (https://rubystyle.guide/)
23+
- Use Ruby's expressive syntax (e.g., unless, ||=, &.)
24+
- Prefer double quotes for strings.
25+
26+
Error Handling and Validation
27+
- Use exceptions for exceptional cases, not for control flow.
28+
- Implement proper error logging and user-friendly messages.
29+
- Use ActiveModel validations in models.
30+
- Handle errors gracefully in controllers and display appropriate flash messages.
31+
32+
UI and Styling
33+
- Use Hotwire (Turbo and Stimulus) for dynamic, SPA-like interactions.
34+
- Use Rails view helpers and partials to keep views DRY.
35+
36+
Performance Optimization
37+
- Use database indexing effectively.
38+
- Implement caching strategies (fragment caching, Russian Doll caching).
39+
- Use eager loading to avoid N+1 queries.
40+
- Optimize database queries using includes, joins, or select.
41+
42+
Key Conventions
43+
- Follow RESTful routing conventions.
44+
- Use concerns for shared behavior across models or controllers.
45+
- Implement service objects for complex business logic.
46+
- Use background jobs (e.g., Sidekiq) for time-consuming tasks.
47+
48+
Testing
49+
- Write comprehensive tests using RSpec.
50+
- Follow TDD/BDD practices.
51+
- Use factories (FactoryBot) for test data generation.
52+
53+
Security
54+
- Implement proper authentication and authorization (e.g., Devise, Pundit).
55+
- Use strong parameters in controllers.
56+
- Protect against common web vulnerabilities (XSS, CSRF, SQL injection).
57+
58+
Follow the official Ruby on Rails guides for best practices in routing, controllers, models, views, and other Rails components.
59+
https://guides.rubyonrails.org/
60+
https://guides.rubyonrails.org/active_record_basics.html
61+
https://guides.rubyonrails.org/active_record_validations.html
62+
https://guides.rubyonrails.org/active_record_callbacks.html
63+
https://guides.rubyonrails.org/association_basics.html
64+
https://guides.rubyonrails.org/active_record_querying.html
65+
https://guides.rubyonrails.org/active_model_basics.html
66+
https://guides.rubyonrails.org/action_controller_overview.html
67+
https://guides.rubyonrails.org/action_controller_advanced_topics.html
68+
https://guides.rubyonrails.org/active_support_core_extensions.html
69+
https://guides.rubyonrails.org/i18n.html
70+
https://guides.rubyonrails.org/testing.html
71+

0 commit comments

Comments
 (0)