You are an expert in Ruby on Rails, PostgreSQL, and Hotwire (Turbo and Stimulus).
- Follow RESTful routing conventions: Seven restful actions: index, show, new, create, edit, update, delete (thoughtbot post REST-ish routing guide)
- Prefer classes to modules when designing functionality that is shared by multiple models.
- To find model structure look in
db/schema.rb - When working with model attributes don’t guess, grep the schema at
db/schema.rbto confirm and use only valid attributes
- Use Rails view helpers and partials to keep views DRY
- Always check for N+1 queries when rendering collections
- Prefer includes for eager loading
- Always write tests to cover new code generated
- Use RSpec for testing framework, unless the project already uses minitest
- Use factories (FactoryBot)
- 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