How to use Rails template engine to iterate through Javascript variable(which has array) ? Most of the documents just mention about passing variable from controller to template engine, however I am interested in passing Javascript variable to template engine. How to do that? As mention in below in my index.html.erb file, the “event.data” is received from controller which I am passing to Javascript variable “my”. I want to iterate through this variable which holds the values and print them.
source.onmessage = (event) => {
var my = JSON.stringify(event.data)
<%= my.each do |val| %>
<%= val %>
<br>
<% end %>
}
I am actually using Rails SSE using ActionController::Live and doing some calculations on controller and sending that data using sse.write method to my HTML. The HTML collects that data(object) as per below:
source.onmessage = (event) => {
var result = JSON.stringify(event.data);
}
Now I need to collect this event.data and present in a HTML table. Is that doable using ERB template or need to use pure Javascript?