- Home
- Skills
- Kaakati
- Rails Enterprise Dev
- Rails Error Prevention
rails-error-prevention_skill
- Shell
6
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill kaakati/rails-enterprise-dev --skill rails-error-prevention- SKILL.md6.7 KB
Overview
This skill provides an expert checklist to prevent common Rails runtime errors before writing code. It focuses on ViewComponents, GROUP BY/Postgres grouping issues, method exposure between layers, N+1 detection, nil guards, and controller/template mistakes. Follow it as a pre-flight to catch mistakes early and avoid runtime debugging.
How this skill works
The skill inspects your planned change against a set of verification steps: check component templates and public methods, ensure helper usage is delegated, validate GROUP BY queries for non-aggregated columns, verify eager-loading patterns to avoid N+1, and confirm controller/view render expectations. It provides concrete shell and Ruby snippets to run in your project and a short checklist for each area to enforce before coding.
When to use it
- Creating or modifying a ViewComponent (ensure template & helpers)
- Writing ActiveRecord GROUP BY or aggregation queries
- Building views that call component methods or service methods
- Debugging undefined method / NoMethodError related to nil or exposure
- Investigating N+1 queries or ambiguous column errors
- Adding or changing controller actions and view templates
Best practices
- Always verify component template pattern (inline vs file) before creating a component
- List view calls and match them to public component methods before writing view code
- Prefix Rails helpers with helpers. inside ViewComponents or delegate them explicitly
- For GROUP BY: include every non-aggregated column in GROUP BY and avoid includes/preload with grouping
- Detect and fix N+1 by using includes/preload/eager_load appropriately and test in console
- Use safe navigation, guard clauses, and early returns to prevent nil-related NoMethodError
Example use cases
- Before adding a new dashboard component: confirm .rb and template exist, list required methods, add delegations or wrappers
- Before converting reports to grouped SQL: ensure selected columns are aggregated or grouped and remove includes from the grouped query
- When a view raises undefined method for component: run the grep checks to list missing methods and add them to the component
- When logs show repeated user queries: add includes(:user) or preload and re-run the console test
- Before adding a controller action: ensure a template exists or the action explicitly renders or redirects
FAQ
Delegate the specific helpers to :helpers in the component class (delegate :link_to, to: :helpers) rather than calling helpers everywhere. This keeps intent explicit and testable.
How do I handle GROUP BY when I need associated records?
Run the aggregation first (group.count) to get keys, then query associated records separately with includes/limits. Avoid combining includes with group in a single query.