Skip to content

Commit 3f6a363

Browse files
committed
refactor: refactor rules file following comments
1 parent bd9bacc commit 3f6a363

File tree

1 file changed

+13
-53
lines changed

1 file changed

+13
-53
lines changed

rails/ai-rules/rails-rules.md

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,31 @@
11
You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus).
22

33
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)
105

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
159

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
2013

2114
Syntax and Formatting
2215
- Follow the Ruby Style Guide (https://rubystyle.guide/)
23-
- Use Ruby's expressive syntax (e.g., unless, ||=, &.)
2416
- Prefer double quotes for strings.
2517

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-
3218
UI and Styling
33-
- Use Hotwire (Turbo and Stimulus) for dynamic, SPA-like interactions.
3419
- Use Rails view helpers and partials to keep views DRY.
3520

3621
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.
4022
- Optimize database queries using includes, joins, or select.
4123

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-
4824
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`
7131

0 commit comments

Comments
 (0)