I prefer to pass data to js with data attributes, it’s easy.
I have something like this in my template
<div
id="app"
data-src="<%= display_path @picture, :large %>"
data-id="<%= @picture.id %>"
data-token="<%= @token %>"></div>
and I retrieve like this in app.js.
const root = document.getElementById('app');
if (root) {
const { src, id, token } = root.dataset;
console.log(src, id, token);
}






















