Skip to content

Instantly share code, notes, and snippets.

@yamitake
Created February 3, 2020 10:13
Show Gist options
  • Save yamitake/8895c04038218becbe4cc38e0cfbdfbb to your computer and use it in GitHub Desktop.
Save yamitake/8895c04038218becbe4cc38e0cfbdfbb to your computer and use it in GitHub Desktop.
ex) = render_async related_products_path(@Product)
$(document).one 'turbolinks:load', ->
if document.documentElement.hasAttribute('data-turbolinks-preview')
return
headers = {}
csrfTokenElement = document.querySelector('meta[name="csrf-token"]')
headers['X-CSRF-Token'] = csrfTokenElement.content if csrfTokenElement
$('div[data-render-async-path]').each (_i, div) ->
$.ajax(
url: $(this).data('render-async-path')
method: 'GET'
headers: headers).done((response) ->
$(div).replaceWith response
return
).fail (response) ->
$('.render_async').replaceWith ''
# frozen_string_literal: true
module RenderAsyncHelper
def render_async(path)
tag.div(data: { render_async_path: path })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment