Calling a ruby program from java script

HI ,

       How can i call a ruby program from java script . I want to

run a ruby program that will post form data on button click .And also
how can I sent username , password form field’s data to a servlet
?Anybody plz help !!!

This is how i used once…

:onchange=>remote_function(:url =>{:action =>
‘update_weekdays’,:controller=>‘calenders’},:with => “‘id=’+this.value”,
:method=>:post)

I’d really like to see the implementation of ruby in your JScript. If
it’s
not too much trouble, would you mind upping it on MediaFire or something
of the likes? I had dabbled with embedded Ruby before but I was never
successful. (Woes of the newbie I guess. :slight_smile:

On Wed, 26 Dec 2007 22:32:13 -0800, Ratnavel S.

Pradeepta S. wrote:

My task is to automate the web service…
when someone opens the client’s site and enters credentials and
clicks button , then ruby script will pick that information from the
fields and after validating redirects to a 3rd party .

Pradeepta,

it is not clear yet what the ‘client site’ (that I will call simply
‘client’ from now on) is:

  1. is it the browser? (you mentioned ‘calling from javascript’ before).
    In this case, as far as I know, you cannot call a ruby program (resident
    in the same computer) from Javascript running in the browser.

  2. is the ‘client’ a Gui tool that needs to invoke a program? depending
    on the platform you are in, there are many possibilities; from a
    rudimentary ‘system’ call (on Unix) to a socket-based communication
    (that would allow the ’ ‘ruby program’ communicate the ‘client site’
    information beyond success/failure).

This would mean that the ‘client’ has to serialize the ‘form’ (with the
user data), and transmit the information to the ‘ruby program’ using
whatever IPC is available (and best for the purpose).

Once we are inside the ruby program, you can use Net::HTTP. I don’t have
direct experience with it, but a quick look at the doc shows several
ways to do a POST request; for example:

url = URI.parse(’…’)
req = Net::HTTP::Post.new(url.path)
req.basic_auth(…)
req.set_form_data({‘user_name’=>’…’, ‘password’=>’…’}, ‘;’)

then the request is sent, etc

In any case, things seem simple; the original ‘form’ is translated into
a hash of key-values (as usual). Of course you have to use the same
names expected by server; but there is no problem in how to ‘transmit
the form’ (that seems a concern of yours).

[You can also look at another library: rest-open-uri (a Ruby gem), that
operates at a higher level than net/http; but this is not your problem
right now].

The point to solve is how the ‘client’ serializes the form (again, not a
problem for a form so simple, whatever language you are using in the GUI
client) and in how you choose to do the IPC.

However the fact that you are so concerned with ‘how to process the
form’ makes me think that something fundamental is still not clear yet
in all this.

I hope this helped however

Raul

Pradeepta S. wrote:

       How can i call a ruby program from java script . I want to

run a ruby program that will post form data on button click .And also
how can I sent username , password form field’s data to a servlet
?Anybody plz help !!!

Pradeepta,

I read the 3 postings (with different titles) that you made recently
on this subject. In the previous post, you mentioned ‘req.set_form_data’
(like you were writing a web service client), now you say that you are
‘in javascript’.

It would help if you clarified this: where is the ‘ruby program’ that
you are trying to call? I have the suspicion that you are trying to call
a ruby program that is in the computer where the browser is (and you
cannot do that).

Or do you mean that the ‘ruby program’ is in the server? in this case
you should just let javascript submit the form (specifying an ‘action’,
the method post, the input fields for user name and password, and the
submit button; there is no ‘programming’ to do). On the server side (I
assume that you are not using Rails), you write a simple Ruby program
which uses CGI to collect the form parameters (and that is presumably
the same program that sent the form).
However I see that in the first post you mentioned a (Java?) ‘servlet’,
so it would seem that the server is already taken care of…

I just wanted to explain why you are getting different answers every
time, as everyone is giving a different interpretation to your question.

Raul

Hi Raul,
Thanx 4 ur suggestion . Actually i m a newbie to ruby and
found it very exciting as I m a java developer ,working 4 an IT MNC . My
task is to automate the web service that we r offering 2 a client.my
tasks are :

  1. when someone opens the client’s site and enters credentials and
    clicks button , then ruby script will pick that information from the
    fields and after validating redirects to a 3rd party .

2.Another script will receive response from client’s site in JSON format
and validates it .

3.Third script checks for IP based authentication

My problem is the first one as I don’t want to use rails and using pure
ruby I want to process form data and forward it to server upon the click
or enter event . can u please help me out ?

Thanks & Regards

Pradeepta

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