Skip to content

Instantly share code, notes, and snippets.

@wrburgess
Created January 9, 2022 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrburgess/4a139eb6cffbab1c7ae3a0a8be2d4f2b to your computer and use it in GitHub Desktop.
Save wrburgess/4a139eb6cffbab1c7ae3a0a8be2d4f2b to your computer and use it in GitHub Desktop.
Rails erb view embed json in html and retrieve with JS dom
const widgetsData = document.querySelector('.widgets-data');
const widgets = JSON.parse(widgetsData.value);
<data class="widgets-data" value='<%= @widgets_json.html_safe %></data>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment