1

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?

2
  • Maybe using node.js.. Commented Nov 29, 2012 at 21:36
  • not quite there yet. but its a lovely tool :) Commented Nov 29, 2012 at 21:45

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
Yes. The webserver has to be able to call the script. It needs an interface to do that. Rack is such an interface.
1

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

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?
Yea you need to be running a server to do what you're trying to do. Look into Sinatra

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.