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