Skip to content

Instantly share code, notes, and snippets.

@minimul
Last active February 16, 2023 15:39
Show Gist options
  • Save minimul/12ab53f87025e0a82b4c19b9cc83f160 to your computer and use it in GitHub Desktop.
Save minimul/12ab53f87025e0a82b4c19b9cc83f160 to your computer and use it in GitHub Desktop.
Turbo Stream Tag Stimulus Controller
//
// 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