button to launch erb scripts and display outputs.

i have a fresh rails application called basic... i have boot strap working and looking to create a button that if pressed will launch a ruby script and display its live output as it happens...

<button type="button" class="btn btn-default">button</button>

<%= 100.times do |i|%> <%= print i*i%> <%= sleep 1%> <%=end%>

i hope some one can point me in the right direction... i love ruby, but never tried rails...

The web page and any javascript in it run in the browser. Which computer do you want the ruby script to run on? The server running your rails app or the client PC running in the browser?

If you answer is the PC running the browser then, for a start, how would you even know that ruby is installed on that PC? It is for exactly that sort of task that javascript was invented.

Colin

Colin Law wrote in post #1182139:

Basically no, you can't do that. There are ways you could make it look as if that is what is happening, but that would not be the sort of thing a beginner could knock off easily. I would get the hang of the conventional web architecture before trying to push the boundaries.

Colin

Colin Law wrote in post #1182154:

Bigmac Turdsplash wrote in post #1182156:

Colin Law wrote in post #1182154:

exactly that sort of task that javascript was invented.

i dont know what im doing, but im excited to learn...

Basically no, you can't do that. There are ways you could make it look as if that is what is happening, but that would not be the sort of thing a beginner could knock off easily. I would get the hang of the conventional web architecture before trying to push the boundaries.

Colin

Maybe just a example for if button is pressed then <=%puts 'hi WORLD'=>

I found gem puma, seems like the right place to start

Puma is the web server that is used as standard by the latest rails versions in development mode. I don't see how that is going to help you.

Perhaps if you explained what you are actually trying to achieve (at a higher level) we may be able to provide a solution.

Colin

Colin Law wrote in post #1182158:

Colin Law wrote in post #1182158:

boundaries.

Colin

Maybe just a example for if button is pressed then <=%puts ‘hi WORLD’=>

I found gem puma, seems like the right place to start

Puma is the web server that is used as standard by the latest rails versions in development mode. I don’t see how that is going to help you.

Perhaps if you explained what you are actually trying to achieve (at a higher level) we may be able to provide a solution.

Colin

With puma i could print live ruby output to the client each line would print as it happens.

I would be very interested to know how to do that.

Colin

I have found the right module actioncontroler::live

That will not let you do what you said you wanted to do, which was put the following on a web page <%= 100.times do |i|%> <%= print i*i%> <%= sleep 1%> <%=end%> and have it update the screen in real time.

I said that was not possible and asked you to tell us what you were actually trying to achieve. Had you answered that question we could probably have saved you a lot of time by pointing you in the right direction.

Colin

Here is a demo that I can make work for my situation. With the actioncontroler::live Module.

10.times do |X| Response.stream.write("hi world #{X}") Sleep 1 End Ensure Response.stream.close

As for a button to trigger the event, ill have to make due with a href=>/liveStream-hiWorld.ntml.erb

Please quote the message you are replying to, this is a mailing list not a forum (though you may be accessing it via a forum like interface) so it is not clear to what you are replying. Thanks.

You specifically requested that the script be embedded in the the web page. Your example is just live streaming from the controller.

I don't think that href will work very well. If you look for examples of using the live feature you will find how to stream into your web page.

Colin

Colin Law wrote in post #1182193:

As for a button to trigger the event, ill have to make due with a href=>/liveStream-hiWorld.ntml.erb

Please quote the message you are replying to, this is a mailing list not a forum (though you may be accessing it via a forum like interface) so it is not clear to what you are replying. Thanks.

You specifically requested that the script be embedded in the the web page. Your example is just live streaming from the controller.

I don't think that href will work very well. If you look for examples of using the live feature you will find how to stream into your web page.

Colin

/messaging/index.html.erb <script> source = new EventSource("/messaging"); source.addEventListener("message", function(response) { // Do something with response.data }, false); </script>

Im using the actioncontroller::live example found on the domentation site, i have things setup properly with routes.rb... I can successfully append data to a <div> in the clients browser. But the browser will keep streaming in a endless loop. Maybe this is expected behaviour?

Bigmac Turdsplash wrote in post #1182233:

Colin Law wrote in post #1182193:

As for a button to trigger the event, ill have to make due with a href=>/liveStream-hiWorld.ntml.erb

Please quote the message you are replying to, this is a mailing list not a forum (though you may be accessing it via a forum like interface) so it is not clear to what you are replying. Thanks.

You specifically requested that the script be embedded in the the web page. Your example is just live streaming from the controller.

I don't think that href will work very well. If you look for examples of using the live feature you will find how to stream into your web page.

Colin

/messaging/index.html.erb <script> source = new EventSource("/messaging"); source.addEventListener("message", function(response) { // Do something with response.data }, false); </script>

Im using the actioncontroller::live example found on the domentation site, i have things setup properly with routes.rb... I can successfully append data to a <div> in the clients browser. But the browser will keep streaming in a endless loop. Maybe this is expected behaviour?

ensure response.stream.close

it seems that this part of the controller does nothing.

if i add to my index.html.erb source.close(); then it will effectively close the stream. so with that said, i could do a if expressions on the client side "if stream_kill, then source.close():"

but this seems a little hacky?

Can you copy/paste the code you are using to do the streaming in the controller please.

Colin