Copilot instructions
.github/instructions/rails-hotwire.instructions.mdRails Hotwire Guide
Copilot instructions
Quality
56/100
Scores the file, not the repository.Length
937 words
24 headings · 0 code blocksRepository
54
— · pushed 410 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Rails Hotwire Guide78## Core Philosophy910- Send HTML over the wire, not JSON - let the server do the rendering11- Achieve SPA-like speed without complex JavaScript frameworks12- Use progressive enhancement - functionality works without JavaScript13- Keep client-side logic minimal and server-side logic rich14- Embrace the simplicity of multi-page applications with the speed of SPAs1516## Turbo Drive Principles1718- Enable fast page navigation without full page reloads automatically19- Intercept all clicks and form submissions by default20- Maintain scroll position and focus between navigations21- Cache pages intelligently for instant back/forward navigation22- Preserve JavaScript state between page visits2324## Turbo Drive Configuration2526- Disable Turbo Drive selectively with `data-turbo="false"`27- Control navigation behavior with `data-turbo-action` attributes28- Use `data-turbo-permanent` to persist elements across navigations29- Configure cache behavior with meta tags30- Handle navigation events for custom behavior3132## Turbo Frames Principles3334- Decompose pages into independent segments that update separately35- Scope navigation to frame boundaries automatically36- Enable partial page updates without custom JavaScript37- Support lazy loading for performance optimization38- Maintain proper URL and history management3940## Turbo Frames Best Practices4142- Use meaningful frame IDs that describe their content43- Keep frames focused on a single concern44- Lazy load below-the-fold content with `loading="lazy"`45- Break out of frames with `data-turbo-frame="_top"` when needed46- Cache frame responses independently for better performance4748## Turbo Streams Principles4950- Update multiple page elements in a single response51- Support real-time updates via WebSockets or SSE52- Use semantic actions: append, prepend, replace, update, remove53- Target elements by ID for surgical updates54- Broadcast changes from models automatically5556## Turbo Streams Implementation5758- Return Turbo Stream responses from form submissions59- Use `turbo_stream` format in controllers60- Broadcast model changes with Action Cable61- Target multiple elements in one response62- Keep stream templates simple and focused6364## Stimulus Philosophy6566- Enhance HTML with just enough JavaScript behavior67- Connect JavaScript objects to DOM elements declaratively68- Use conventions to minimize configuration69- Keep controllers small and focused70- Leverage the power of mutation observers7172## Stimulus Controller Principles7374- Name controllers based on their behavior, not their content75- Keep controllers focused on a single responsibility76- Use data attributes for all configuration77- Prefer composition over inheritance78- Write controllers that can be reused across pages7980## Stimulus Targets8182- Define targets for elements the controller will manipulate83- Use semantic target names that describe their purpose84- Check for target existence before using them85- Use singular targets for single elements86- Use plural targets for collections of elements8788## Stimulus Actions8990- Declare all event handling in HTML with data attributes91- Use descriptive action names that explain the behavior92- Handle events at the appropriate level in the DOM93- Prevent default behavior explicitly when needed94- Keep action methods small and focused9596## Stimulus Values9798- Use values for controller configuration and state99- Define value types for automatic parsing100- React to value changes with callbacks101- Set sensible defaults for all values102- Keep values primitive and serializable103104## Stimulus Classes105106- Define CSS classes as data attributes for flexibility107- Use classes for styling state changes108- Keep class names semantic and reusable109- Allow classes to be configured per instance110- Document required CSS classes clearly111112## Hotwire Integration Patterns113114- Use Turbo Frames for partial page updates115- Use Turbo Streams for multi-element updates116- Use Stimulus for client-side interactivity117- Combine all three for rich, responsive interfaces118- Keep each tool focused on its strength119120## Progressive Enhancement121122- Build features that work without JavaScript first123- Enhance with Turbo for better navigation124- Add Stimulus for rich interactions125- Test with JavaScript disabled126- Provide meaningful fallbacks127128## Performance Optimization129130- Use Turbo Frames to update only what changes131- Lazy load expensive content132- Cache aggressively with proper cache keys133- Minimize Stimulus controller complexity134- Preload critical resources135136## Testing Strategies137138- Write system tests for user flows139- Test Turbo Frame interactions140- Test Turbo Stream responses141- Test Stimulus controllers in isolation142- Ensure graceful degradation143144## Error Handling145146- Handle Turbo visit errors gracefully147- Provide feedback for failed form submissions148- Show meaningful error messages149- Implement retry mechanisms for failed requests150- Log errors appropriately for debugging151152## Mobile Considerations153154- Ensure touch targets are appropriately sized155- Handle touch events properly in Stimulus156- Test on real devices, not just responsive mode157- Optimize for slower network connections158- Consider offline capabilities159160## Security Practices161162- Always verify permissions server-side163- Use CSRF tokens in all forms164- Sanitize any user-generated content165- Don't trust client-side validation166- Implement proper authentication checks167168## Development Workflow169170- Use Rails generators for Stimulus controllers171- Organize controllers by feature172- Keep JavaScript minimal and focused173- Test JavaScript behavior through system tests174- Document complex interactions175176## Debugging Techniques177178- Use Turbo debugging events in development179- Log Stimulus lifecycle methods when troubleshooting180- Inspect Turbo Frame sources in browser tools181- Monitor WebSocket connections for streams182- Use browser console for interactive debugging183184## Best Practices185186- Let the server handle complex logic187- Keep JavaScript simple and declarative188- Use semantic HTML as the foundation189- Follow Rails conventions consistently190- Write code that's a joy to maintain191192Remember: Hotwire is about sending HTML over the wire. Keep your client-side code minimal and let Rails do what it does best - render HTML on the server.193
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-controllers.instructions.md · 54 | Copilot instructions | teststylesecurityapi+1 | 56/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-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-controllers.instructions.md Diff against .github/instructions/rails-deployment.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
