From 437f52c0da61cba2d4b77ab7657adcc21e512290 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Fri, 25 Jul 2025 10:12:11 +0200 Subject: [PATCH 1/4] feat: define Thoughtbot rules for AI-enabled IDEs Add thoughtbot Rails AI development rules Create AI rules for AI-assisted Rails development. --- rails/ai-rules/rails-rules.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 rails/ai-rules/rails-rules.md diff --git a/rails/ai-rules/rails-rules.md b/rails/ai-rules/rails-rules.md new file mode 100644 index 00000000..4544acd7 --- /dev/null +++ b/rails/ai-rules/rails-rules.md @@ -0,0 +1,33 @@ +# IDE AI thoughtbot rules + +You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus). + +## Key Conventions + +- 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) +- Use concerns for shared behavior across models or controllers + +## Data / Models + +- To find model structure look in `db/schema.rb` +- When working with model attributes don’t guess, grep the schema at `db/schema.rb` to confirm and use only valid attributes + +## UI and Styling + +- Use Rails view helpers and partials to keep views DRY + +## Performance Optimization + +- Always check for N+1 queries when rendering collections +- Prefer includes for eager loading +- Scope queries to only the fields needed with select + +## Testing + +- Always write tests to cover new code generated +- Use RSpec for testing framework +- Use factories (FactoryBot) (https://thoughtbot.github.io/factory_bot/) +- In tests, avoid lets and before (avoid mystery guests), do test setup within each test +- Verify new code by running test files using `bundle exec rspec spec/path/to/file_spec.rb` +- 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` + From cddf211dbc4858824613a4c66a1c97e89daaba32 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Fri, 26 Sep 2025 09:20:22 +0100 Subject: [PATCH 2/4] prefer classes over modules --- rails/ai-rules/rails-rules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rails/ai-rules/rails-rules.md b/rails/ai-rules/rails-rules.md index 4544acd7..81f2aa04 100644 --- a/rails/ai-rules/rails-rules.md +++ b/rails/ai-rules/rails-rules.md @@ -5,7 +5,7 @@ You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus) ## Key Conventions - 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) -- Use concerns for shared behavior across models or controllers +- Prefer classes to modules when designing functionality that is shared by multiple models. ## Data / Models From 78827e497b871cd1938de69ce017ded702f3d4a6 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Fri, 26 Sep 2025 09:22:21 +0100 Subject: [PATCH 3/4] use Rspec unless minitest is present --- rails/ai-rules/rails-rules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rails/ai-rules/rails-rules.md b/rails/ai-rules/rails-rules.md index 81f2aa04..874233fb 100644 --- a/rails/ai-rules/rails-rules.md +++ b/rails/ai-rules/rails-rules.md @@ -25,7 +25,7 @@ You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus) ## Testing - Always write tests to cover new code generated -- Use RSpec for testing framework +- Use RSpec for testing framework, unless the project already uses minitest - Use factories (FactoryBot) (https://thoughtbot.github.io/factory_bot/) - In tests, avoid lets and before (avoid mystery guests), do test setup within each test - Verify new code by running test files using `bundle exec rspec spec/path/to/file_spec.rb` From e86908eb36d91306a39ec1018ba43cc13ff9e615 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Fri, 26 Sep 2025 09:23:11 +0100 Subject: [PATCH 4/4] do not make premature suggestions about queries --- rails/ai-rules/rails-rules.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rails/ai-rules/rails-rules.md b/rails/ai-rules/rails-rules.md index 874233fb..e4808b30 100644 --- a/rails/ai-rules/rails-rules.md +++ b/rails/ai-rules/rails-rules.md @@ -4,7 +4,7 @@ You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus) ## Key Conventions -- 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) +- Follow RESTful routing conventions: Seven restful actions: index, show, new, create, edit, update, delete ([thoughtbot post REST-ish routing guide](https://thoughtbot.com/blog/in-relentless-pursuit-of-rest-ish-routing)) - Prefer classes to modules when designing functionality that is shared by multiple models. ## Data / Models @@ -20,14 +20,12 @@ You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus) - Always check for N+1 queries when rendering collections - Prefer includes for eager loading -- Scope queries to only the fields needed with select ## Testing - Always write tests to cover new code generated - Use RSpec for testing framework, unless the project already uses minitest -- Use factories (FactoryBot) (https://thoughtbot.github.io/factory_bot/) +- Use factories ([FactoryBot](https://thoughtbot.github.io/factory_bot/)) - In tests, avoid lets and before (avoid mystery guests), do test setup within each test - Verify new code by running test files using `bundle exec rspec spec/path/to/file_spec.rb` - 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` -