call a ruby script from html

M

Mario Ruiz

I would like to call a ruby script from a html page passing a few
parameters, something like:
<a href="c:/myS/search.rb param1 param2">Search</a>

Anybody knows how to do it?

Thanks.
 
R

Richard Conroy

[Note: parts of this message were removed to make it a legal post.]

Not too sure what you are trying to do here. The fact that you are invoking
against your local system is a bit weird, and I dont think that is workable.
Might work for locally loaded Javascript, but not in a HREF.

If you are hitting a server, this can be made to work, as CGI (similar to
how
you would invoke against a PHP script), but CGI is not a popular way to
run Ruby web apps, and it is very poorly documented in general (its eclipsed
by all the other methods).

Again, your parameters would have to be appropriate for a query string, you
couldn't
rely on passing them in as command line arguments.

For isntance:

<a href="/scripts/ruby.rb?param1=value1&param2=value2">Search<a>
 
M

Mario Ruiz

What I'm trying to do is to call a ruby script that admits parameters.
This program is going to be run locally.
The problem is no parameters are taken since the explorers try to
download the file instead of running the file.

Another way to solve this would be to run directly the code on the
page... is that possible?

Thanks
 
M

Mario Antonetti

[Note: parts of this message were removed to make it a legal post.]

Not too sure what you are trying to do here. The fact that you are invoking
against your local system is a bit weird, and I dont think that is
workable.
Might work for locally loaded Javascript, but not in a HREF.

If you are hitting a server, this can be made to work, as CGI (similar to
how
you would invoke against a PHP script), but CGI is not a popular way to
run Ruby web apps, and it is very poorly documented in general (its
eclipsed
by all the other methods).

Again, your parameters would have to be appropriate for a query string, you
couldn't
rely on passing them in as command line arguments.

For isntance:

<a href="/scripts/ruby.rb?param1=value1&param2=value2">Search<a>



If the ruby script doesn't rely on being run on the server, you could try
HotRuby: http://hotruby.yukoba.jp/
 
R

Richard Conroy

[Note: parts of this message were removed to make it a legal post.]

What I'm trying to do is to call a ruby script that admits parameters.
This program is going to be run locally.
The problem is no parameters are taken since the explorers try to
download the file instead of running the file.

Another way to solve this would be to run directly the code on the
page... is that possible?
There are a couple of exotic ways to run ruby in your browser. All of them
work like
Java applets.

You can Jar up your ruby code with JRuby, and you might be able to locally
invoke on
it that way.

A similar method works for IronRuby, to get your Ruby code inside a
silverlight applet.
 
M

Martin Boese

What I'm trying to do is to call a ruby script that admits
parameters. This program is going to be run locally.
The problem is no parameters are taken since the explorers try to
download the file instead of running the file.

Another way to solve this would be to run directly the code on the
page... is that possible?

Thanks

I don't know of any browser what would execute the file, even if
the page was loaded locally....

But running a small local webserver will work. Ruby the code below and
then link to http://localhost:4000/run .

require 'webrick'

class RunScript < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
system("c:/myS/search.rb param1 param2")
res.status = 200
res['Content-Type'] = 'text/html'
res.body = "<h1>Running Program</h1>"
end
end


server = WEBrick::HTTPServer.new:)Port => 4000)
server.mount("/run", RunScript)

trap("INT"){ server.shutdown }
server.start
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top