Created
February 3, 2020 10:13
-
-
Save yamitake/8895c04038218becbe4cc38e0cfbdfbb to your computer and use it in GitHub Desktop.
ex) = render_async related_products_path(@Product)
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
$(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 '' |
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
# 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