I have a ruby file on my server (a simple test file). I am wondering how I can use javascript to execute that file on server with a button click. Nothing fancy I want here like rails or asp or php. Its just a small test and I want to see how far it goes. On terminal, all I have to do is ruby test.rb. Is there a way to do this with javascript on an html page?
-
Maybe using node.js..knownasilya– knownasilya2012-11-29 21:36:29 +00:00Commented Nov 29, 2012 at 21:36
-
not quite there yet. but its a lovely tool :)user1758162– user17581622012-11-29 21:45:00 +00:00Commented Nov 29, 2012 at 21:45
Add a comment
|
2 Answers
Adapt the script so your webserver can access it with a Rack or CGI.
Then you just need to make an HTTP request to it. You could set location = URI, call submit() on a form, use XMLHttpRequest or any of a host of other options.
2 Comments
user1758162
well its a static website , pure HTML/CSS/JS . I have contact form. I wrote a ruby script so that it uses
mail command to send an email. Will Rack help here?Quentin
Yes. The webserver has to be able to call the script. It needs an interface to do that. Rack is such an interface.
Well browsers don't run Ruby, so I think you need to send a request with that button click to your server, and then the server will run the file.
Try Sinatra: http://www.sinatrarb.com/
2 Comments
user1758162
well its a static website , pure HTML/CSS/JS . I have contact form. I wrote a ruby script so that it uses
mail command to send an email. Will sinatra help here?AJcodez
Yea you need to be running a server to do what you're trying to do. Look into Sinatra