|
| 1 | +# IDE AI thoughtbot rules |
| 2 | + |
1 | 3 | You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus).
|
2 | 4 |
|
3 | 5 | 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 | 6 |
|
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. |
| 7 | +- Follow thoughtbot's guide to write idiomatic Ruby (https://github.com/thoughtbot/guides/tree/main/ruby) |
| 8 | + |
| 9 | +Key Conventions |
| 10 | + |
| 11 | +- Follow RESTful routing conventions: Seven restful actions: index, show, new, create, edit, update, delete (https://thoughtbot.com/blog/in-relentless-pursuit-of-rest-ish-routing) |
| 12 | +- Use concerns for shared behavior across models or controllers |
| 13 | + |
| 14 | +Data / Models |
15 | 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. |
| 16 | +- To find model structure look in `db/schema.rb` |
| 17 | +- When working with model attributes don’t guess, grep the schema at `db/schema.rb` to confirm and use only valid attributes |
20 | 18 |
|
21 | 19 | Syntax and Formatting
|
| 20 | + |
22 | 21 | - Follow the Ruby Style Guide (https://rubystyle.guide/)
|
23 |
| -- Use Ruby's expressive syntax (e.g., unless, ||=, &.) |
24 | 22 | - Prefer double quotes for strings.
|
25 | 23 |
|
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 | 24 | UI and Styling
|
33 |
| -- Use Hotwire (Turbo and Stimulus) for dynamic, SPA-like interactions. |
| 25 | + |
34 | 26 | - Use Rails view helpers and partials to keep views DRY.
|
35 | 27 |
|
36 | 28 | 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 | 29 |
|
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. |
| 30 | +- Optimize database queries using includes, joins, or select. |
47 | 31 |
|
48 | 32 | 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 | 33 |
|
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 |
| 34 | +- Use factories (FactoryBot) for test data generation (https://thoughtbot.github.io/factory_bot/) |
| 35 | +- Always write tests to cover new code generated |
| 36 | +- Prefer RSpec for Rails applications but use the existing test framework if there is one |
| 37 | +- In tests, avoid lets and before (avoid mystery guests), do test setup within each test |
| 38 | +- Verify new code by running test files using `bundle exec rspec spec/path/to/file_spec.rb` |
| 39 | +- You can run a specific test by appending the line number (it can be any line number starting from the "it" block of the test) eg. `bundle exec rspec spec/path/to/file_spec.rb:72` |
71 | 40 |
|
0 commit comments