From 1cd2593f74441e20908a0b280697700eb1de8997 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Fri, 25 Jul 2025 10:12:11 +0200 Subject: [PATCH] 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 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 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..8ef14358 --- /dev/null +++ b/rails/ai-rules/rails-rules.md @@ -0,0 +1,31 @@ +# 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 + +- Optimize database queries using includes, joins, or select + +## Testing + +- Always write tests to cover new code generated +- Prefer RSpec for Rails applications but use the existing test framework if there is one +- 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` +