Add turbo_search_form_for helper for Turbo/Hotwire integration#1611
Add turbo_search_form_for helper for Turbo/Hotwire integration#1611scarroll32 merged 16 commits intomainfrom
Conversation
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
scarroll32
left a comment
There was a problem hiding this comment.
@copilot the CI is failing please fix it
|
@Greyoxide can you please review this PR and tell me what you think (refer #1382 ) |
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
|
@copilot please try again you were rate limited |
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
scarroll32
left a comment
There was a problem hiding this comment.
@copilot the CI has failed, please fix it
|
@copilot the CI has failed, please fix it |
scarroll32
left a comment
There was a problem hiding this comment.
Please simplify the code as noted in the other comment
| # instead of traditional HTML GET requests. Useful for seamless integration with | ||
| # paginated results and other turbo-enabled components. | ||
| # | ||
| def turbo_search_form_for(record, options = {}, &proc) |
There was a problem hiding this comment.
@copilot this method is long with a complex if/else. Can it be broken down into smaller methods and handle the conditional logic with returns if true / false ?
Each method can then be individually tested
There was a problem hiding this comment.
Refactored both search_form_for and turbo_search_form_for methods into smaller, testable units. Extracted common logic into private methods:
extract_search_and_set_url- handles search object validation and URL settingbuild_turbo_options- constructs turbo-specific data attributesbuild_html_options- builds base HTML options for formsfinalize_form_options- sets final form configuration
Each method can now be individually tested and the complex conditional logic is simplified with early returns. Added comprehensive tests for all private methods. Fixed in commit a249cfa.
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Simplified the code by refactoring into smaller, focused methods as requested. The complex conditional logic has been broken down into individually testable private methods with proper separation of concerns. Fixed in commit a249cfa. |
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Fixed the CI failure by removing unreliable |
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
Fixed the CI failure by correcting the data attribute format for Rails form helpers. The previous implementation used flat string keys like |
✅ COMPLETED: Create turbo-enabled search form helper for Ransack
Problem Solved
The original issue was that
search_form_foris hardcoded to usemethod: :get, preventing turbo stream requests and causing controller complexity when combining search with pagination (Kaminari).Solution Implemented
Created a new
turbo_search_form_forhelper that provides turbo stream support while maintaining full backward compatibility.Changes Made:
turbo_search_form_formethod inlib/ransack/helpers/form_helper.rbspec/ransack/helpers/form_helper_spec.rbdocs/docs/getting-started/simple-mode.mdsearch_form_forunchangedcaller_locationsusageKey Features:
🚀 Turbo-native: Uses POST method and turbo data attributes by default
🎯 Targeted updates: Supports
turbo_framefor precise DOM updates⚙️ Configurable: Custom HTTP methods, turbo actions, and all original options
🔄 Seamless integration: Works perfectly with Kaminari pagination
🛡️ Backward compatible: Zero breaking changes to existing code
🧪 Well-tested: Individual method tests for better coverage and maintainability
🔧 Reliable: Fixed CI issues with robust, environment-agnostic code
🎯 Rails-compliant: Proper data attribute format for form helper compatibility
Latest Fix:
:datahash with symbol keys, not as flat string keys like'data-turbo-action'.{ 'data-turbo-action' => 'advance', 'data-turbo-frame' => 'results' }{ data: { turbo_action: 'advance', turbo_frame: 'results' } }Code Structure:
Usage Examples:
Controller Benefits:
Before: Complex format handling required
After: Simplified - turbo handles everything seamlessly
Result: Controllers become simpler, UX improves with seamless search/pagination, and no breaking changes to existing code. The implementation provides a surgical solution that directly addresses the original issue with proper test isolation, maintainable code structure, reliable CI execution across different environments, and full Rails form helper compatibility.
Additional instructions:
Fixes #1382
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.