Last active
February 16, 2023 15:39
-
-
Save minimul/12ab53f87025e0a82b4c19b9cc83f160 to your computer and use it in GitHub Desktop.
Turbo Stream Tag Stimulus Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Rails View | |
// <%= tag.div data: { 'turbo-stream-tag-target': 'loadForm' } %> | |
// Stimulus Controller turbo_stream_tag_controller.js | |
// .. | |
loadFormTargetConnected (el) { | |
// propertyUrlValue was set on data-controller as a value | |
sendStream(this.propertyUrlValue, { property_id: el.value }) | |
} | |
// from a utils.js - imported in as sendStream | |
import { get } from '@rails/request.js' | |
export async function sendStream (url, params = {}) { | |
const response = await get(url, { responseKind: 'turbo-stream', query: params }) | |
if (response.ok) { | |
return response | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment