Copilot instructions
.github/instructions/rails-controllers.instructions.mdRails Controllers Guide
Copilot instructions
Quality
56/100
Scores the file, not the repository.Length
747 words
23 headings · 0 code blocksRepository
54
— · pushed 410 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Rails Controllers Guide78## Core Philosophy910- Controllers handle HTTP requests and responses only11- Keep controllers thin and focused12- Business logic belongs in models or service objects13- Follow RESTful conventions strictly14- Design for clarity and maintainability1516## Controller Design Principles1718- One controller per resource19- Seven standard RESTful actions maximum20- Keep actions focused on single responsibilities21- Handle multiple response formats gracefully22- Maintain consistent patterns across controllers2324## RESTful Actions2526- Use only standard actions when possible: index, show, new, create, edit, update, destroy27- Add custom actions sparingly and thoughtfully28- Name custom actions with clear verbs29- Group related actions in the same controller30- Consider splitting into multiple resources instead of custom actions3132## Before Actions3334- Use before_action for common setup tasks35- Keep filter methods private36- Order filters from general to specific37- Document filter purposes when not obvious38- Avoid complex logic in filters3940## Strong Parameters4142- Always use strong parameters for user input43- Define parameter methods as private44- Be explicit about permitted attributes45- Handle nested attributes appropriately46- Document complex parameter structures4748## Response Handling4950- Support multiple formats (HTML, JSON, Turbo Stream)51- Use consistent status codes52- Provide meaningful error messages53- Handle missing records gracefully54- Implement proper content negotiation5556## Error Handling5758- Rescue specific exceptions at appropriate levels59- Provide user-friendly error messages60- Log errors with sufficient context61- Use proper HTTP status codes62- Handle errors consistently across controllers6364## Authentication and Authorization6566- Implement authentication in ApplicationController67- Check authorization in before_action callbacks68- Fail fast with unauthorized access69- Provide clear feedback for access denied70- Keep authorization logic simple and clear7172## Controller Concerns7374- Extract shared behavior into concerns75- Name concerns based on functionality76- Keep concerns focused and cohesive77- Document concern dependencies78- Test concerns in isolation7980## Flash Messages8182- Use flash for user notifications83- Keep messages clear and actionable84- Use consistent message keys85- Handle flash in layouts appropriately86- Consider flash.now for rendered responses8788## Redirects vs Rendering8990- Redirect after successful mutations91- Render on validation failures92- Preserve user input when rendering93- Use proper status codes94- Maintain RESTful patterns9596## Parameter Handling9798- Validate parameters early99- Handle missing parameters gracefully100- Transform parameters consistently101- Document parameter expectations102- Use parameter objects for complex inputs103104## Response Formats105106- Design API responses thoughtfully107- Keep JSON responses consistent108- Use Turbo Streams for partial updates109- Support format negotiation properly110- Document response structures111112## Testing Controllers113114- Test authorization and authentication115- Verify response formats and status codes116- Check parameter filtering117- Test error scenarios118- Keep controller tests focused on HTTP concerns119120## Performance Considerations121122- Implement pagination for index actions123- Use includes to prevent N+1 queries124- Cache expensive operations appropriately125- Limit response data to necessary fields126- Monitor controller action performance127128## Security Best Practices129130- Never trust user input131- Verify authorization for every action132- Use CSRF protection consistently133- Implement rate limiting where appropriate134- Audit controller access patterns135136## API Design (When Needed)137138- Version APIs from the start139- Use consistent response formats140- Implement proper error responses141- Document all endpoints thoroughly142- Consider API-only controllers143144## Turbo Integration145146- Return Turbo Stream responses for AJAX requests147- Use proper Turbo Frame targeting148- Handle Turbo Drive visits appropriately149- Implement graceful fallbacks150- Test Turbo interactions thoroughly151152## Controller Inheritance153154- Use ApplicationController for shared behavior155- Create base controllers for common patterns156- Keep inheritance hierarchies shallow157- Document inheritance purposes158- Avoid deep controller hierarchies159160## Common Anti-Patterns161162- Avoid business logic in controllers163- Don't query databases directly in views164- Prevent controllers from knowing model internals165- Skip complex conditionals in actions166- Don't duplicate code across controllers167168## Refactoring Guidelines169170- Extract complex logic to service objects171- Move view logic to helpers or decorators172- Consolidate duplicate code into concerns173- Split large controllers by resource174- Keep actions under 10 lines when possible175176## Best Practices Summary177178- Keep controllers thin and focused179- Follow RESTful conventions180- Handle errors gracefully181- Use strong parameters always182- Test HTTP concerns thoroughly183184Remember: Controllers are just the translation layer between HTTP and your application. Keep them simple and let other layers handle complexity.185
Also in levifig/rails-instructions
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| levifig/rails-instructions.github/instructions/rails-core.instructions.md · 54 | Copilot instructions | teststylearchtesting-strategy+5 | 68/100 | 3 days ago | |
| levifig/rails-instructions.cursor/rules/guidelines.mdc · 54 | Cursor rules | teststyletesting-strategysecurity+4 | 71/100 | 3 days ago | |
| levifig/rails-instructions.cursor/rules/rails-rules.mdc · 54 | Cursor rules | testlint-formatstylearch+9 | 84/100 | 3 days ago | |
| levifig/rails-instructions.github/copilot-instructions.md · 54 | Copilot instructions | teststyletesting-strategysecurity+4 | 71/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-api.instructions.md · 54 | Copilot instructions | testlint-formatstyletesting-strategy+7 | 67/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-background-jobs.instructions.md · 54 | Copilot instructions | teststyletesting-strategydatabase+2 | 63/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-deployment.instructions.md · 54 | Copilot instructions | setupstylesecuritydatabase+2 | 52/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-hotwire.instructions.md · 54 | Copilot instructions | teststylesecurityperformance+1 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-importmaps.instructions.md · 54 | Copilot instructions | teststylesecuritydatabase+2 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-mobile.instructions.md · 54 | Copilot instructions | styleuiperformance | 66/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-models.instructions.md · 54 | Copilot instructions | teststylearchtypes+4 | 60/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-performance.instructions.md · 54 | Copilot instructions | teststylegitdatabase+2 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-security.instructions.md · 54 | Copilot instructions | teststylesecuritydependencies+3 | 63/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-services.instructions.md · 54 | Copilot instructions | teststylearchtesting-strategy+4 | 75/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-styling.instructions.md · 54 | Copilot instructions | styledatabaseuiperformance+3 | 59/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-testing.instructions.md · 54 | Copilot instructions | teststyletesting-strategysecurity+2 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-views.instructions.md · 54 | Copilot instructions | teststylearchsecurity+3 | 60/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails.instructions.md · 54 | Copilot instructions | testlint-formatstylearch+9 | 84/100 | 3 days ago |
Diff against .github/instructions/rails-core.instructions.md Diff against .cursor/rules/guidelines.mdc Diff against .cursor/rules/rails-rules.mdc Diff against .github/copilot-instructions.md Diff against .github/instructions/rails-api.instructions.md Diff against .github/instructions/rails-background-jobs.instructions.md Diff against .github/instructions/rails-deployment.instructions.md Diff against .github/instructions/rails-hotwire.instructions.md Diff against .github/instructions/rails-importmaps.instructions.md Diff against .github/instructions/rails-mobile.instructions.md Diff against .github/instructions/rails-models.instructions.md Diff against .github/instructions/rails-performance.instructions.md Diff against .github/instructions/rails-security.instructions.md Diff against .github/instructions/rails-services.instructions.md Diff against .github/instructions/rails-styling.instructions.md Diff against .github/instructions/rails-testing.instructions.md Diff against .github/instructions/rails-views.instructions.md Diff against .github/instructions/rails.instructions.md
