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

<%= 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…

On 12 March 2016 at 07:34, Bigmac T. [email protected]
wrote:

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

On 12 March 2016 at 17:46, Bigmac T. [email protected]
wrote:

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

Colin L. wrote in post #1182154:

On 12 March 2016 at 17:46, Bigmac T. [email protected]
wrote:

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’=>

Colin L. wrote in post #1182139:

On 12 March 2016 at 07:34, Bigmac T. [email protected]
wrote:

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

no, i want to run ruby code on the server and display the console output
to the viewer in real time as each line is displayed

<%=# if button is pressed=>
button

<%=100.times do |x| puts x; sleep 1; end=>

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

Bigmac T. wrote in post #1182156:

Colin L. wrote in post #1182154:

On 12 March 2016 at 17:46, Bigmac T. [email protected]
wrote:

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

On 13 March 2016 at 02:55, Bigmac T. [email protected]
wrote:

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 L. wrote in post #1182158:

On 13 March 2016 at 02:55, Bigmac T. [email protected]
wrote:

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.

But i hope to print data to a

or

when a button is pressed <%=
puts ’

hi

’ =>

I have found the right module actioncontroler::live

On 13 Mar 2016 19:08, “Bigmac T.” [email protected] wrote:

Colin L. wrote in post #1182158:

On 13 March 2016 at 02:55, Bigmac T. [email protected]
wrote:

boundaries.

Colin

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

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

But i hope to print data to a

or

when a button is pressed <%=
puts ’

hi

’ =>


Posted via http://www.ruby-forum.com/.


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected]
To post to this group, send email to [email protected]
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/eaf977148895c72331d409f0899dbae3%40ruby-forum.com
.

https://youtu.be/O9w_hxoxtW0

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

On 13 March 2016 at 22:50, Bigmac T. [email protected]
wrote:

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

On 14 March 2016 at 16:15, Bigmac T. [email protected]
wrote:

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 L. wrote in post #1182193:

On 14 March 2016 at 16:15, Bigmac T. [email protected]
wrote:

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

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

in the clients browser.
But the browser will keep streaming in a endless loop. Maybe this is
expected behaviour?

Bigmac T. wrote in post #1182233:

Colin L. wrote in post #1182193:

On 14 March 2016 at 16:15, Bigmac T. [email protected]
wrote:

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

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

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?

On 16 March 2016 at 01:24, Bigmac T. [email protected]
wrote:

interface) so it is not clear to what you are replying. Thanks.
/messaging/index.html.erb
But the browser will keep streaming in a endless loop. Maybe this is
expected behaviour?

ensure
response.stream.close

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

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs