| name | Rails Context Verification |
| description | Systematic verification of codebase context before code generation to prevent assumption bugs. Use when: (1) Working in unfamiliar namespace, (2) Using authentication helpers, (3) Copying patterns across namespaces, (4) Before any code generation. Trigger keywords: context, assumptions, helpers, authentication, current_user, verify, validate context |
| version | 1.2.0 |
| category | implementation |
Rails Context Verification
Prevent "assumption bugs" by verifying codebase context before generating code.
Context Verification Decision Tree
What are you generating?
│
├─ View with authentication
│ └─ Verify: rg "def current_" app/controllers/
│
├─ Controller with auth check
│ └─ Verify: rg "devise_for" config/routes.rb
│
├─ Route helpers (link_to, redirect_to)
│ └─ Verify: rails routes | grep namespace
│
├─ Instance variables in view
│ └─ Verify: rg "@variable\s*=" controller_file
│
├─ Custom helper method
│ └─ Verify: rg "def helper_name" app/helpers/
│
└─ Copying pattern from other namespace
└─ STOP! Search target namespace for actual patterns
NEVER Do This
NEVER assume authentication helper names:
<%= current_admin.email %>
<%= current_administrator.email %>
NEVER assume Devise scope matches model name:
before_action :authenticate_admin!
before_action :authenticate_administrator!
NEVER assume route prefixes:
<%# WRONG - Assuming singular prefix %>
<%= link_to "Dashboard", admin_dashboard_path %>
<%# RIGHT - Verify: rails routes | grep admin → shows admins_ (plural) %>
<%= link_to "Dashboard", admins_dashboard_path %>
NEVER copy patterns across namespaces without verification:
before_action :set_account
before_action :authenticate_administrator!
NEVER use instance variables without verifying they're set:
<%# WRONG - Using @current_account without verification %>
<%= @current_account.name %> # NIL ERROR if not set!
<%# RIGHT - Check controller first %>
<%# rg "@current_account\s*=" controller_file %>
<%# Not found? Don't use it. %>
Core Verification Protocol
Before ANY Code Generation
- Identify Namespace: Admin? Client? API? Public?
- Search for Patterns: Don't invent - discover
- Use Verified Names: Only what search confirms exists
- Document Context: Record verified helpers for team
Quick Verification Commands
| What | Command |
|---|
| Authentication helper | rg "def current_" app/controllers/ |
| Signed-in? helper | rg "signed_in\?" app/views/namespace/ |
| Devise scope | rg "devise_for" config/routes.rb |
| Route helpers | rails routes | grep namespace |
| View helpers | rg "def helper_name" app/helpers/ |
| Instance variables | rg "@variable\s*=" controller_file |
| Before actions | rg "before_action" base_controller.rb |
| Model methods | rg "def method_name" app/models/ |
| Factories | rg "factory :name" spec/factories/ |
Verification Checklist
For Views
For Controllers
For Tests
Namespace-Specific Patterns
| Namespace | Authentication | Route Prefix | Base Controller |
|---|
| Admin | current_administrator, administrator_signed_in? | admins_ | Admins::BaseController |
| Client | current_user, user_signed_in? | clients_ | Clients::BaseController |
| API | Token-based | api_v1_ | Api::BaseController |
| Public | None or optional | Default | ApplicationController |
Warning: These are examples. Your codebase may differ. Always verify!
Context Documentation Format
When delegating to specialists, include verified context:
**Verified Context:**
- Namespace: admin
- Auth helper: `current_administrator` (verified: app/controllers/application_controller.rb:42)
- Route prefix: `admins_` (verified: rails routes)
- Authorization: `require_super_admin` (verified: base_controller.rb:8)
CRITICAL: Use ONLY these verified helpers. Do not assume others exist.
Remember
- Never assume - always verify helper names, routes, methods
- Search first - discover patterns before applying them
- Namespace matters - admin ≠ client ≠ api (different patterns)
- Devise scope matters - :users ≠ :admins ≠ :administrators
- 2 minutes to verify saves hours of debugging
References
Detailed examples and commands in references/:
verification-commands.md - Complete search command reference
pattern-discovery-examples.md - Real-world verification workflows
workflow-integration.md - Implementation workflow integration, beads tracking