Not sure if this is even possible but here’s what I have, and what I wish to achieve.
I have an Admin page on my site with a whole load of links that start either a background job, or another small method).
Is there a way I can sort of show the “puts” output of these into a textarea or div on the Admin page so I can go there and view the output without having to SSH into my server? I don’t want the entirety of the logs, just the “puts” output that i’ve defined.
May just make it easier to see what’s happening.
I also want to be able to leave the page and go back and see the history. I will also think about adding a clear button that can be used before i click another button to do something new.
I can’t say that I know much about how your setup is working, or even what puts is (I assume it’s just string-logging). But, if I was going to do something like this in the simplest way possible, I’d probably just log the values to a database (maybe even something like Redis, where it could have a short Time to Live). Then, on the client-side, I’d use something like a Server Sent Event (SSE) stream to just poll the server to return the logged data.
I’m still very new to Hotwire, so I don’t want to give too many details (as I don’t have them). But, persisting the data temporarily seems like it will be the easiest approach.
I’m actually curious to see how SSE and Hotwire works together (which apparently it has mechanics for).
Like BenNadel suggested, I’d also save the puts output to a database record.
I’d also use a turbo_stream to signal to my page that there are new updates to that record.
Or first step: you could just have a lazy-loaded turbo_frame (that loads when it’s opened, closed up under say under a <details> tag), to read that record, and to just .reload() that turbo_frame every 3 seconds.