# Passing arguments to ruby script

**URL:** <https://www.ruby-forum.com/t/passing-arguments-to-ruby-script/109456>\
**Category:** Ruby\
**Created:** [July 15, 2007, 5:06am UTC](https://www.ruby-forum.com/t/passing-arguments-to-ruby-script/109456 "2007-07-15T05:06:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![galecho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@galecho](https://www.ruby-forum.com/u/galecho)\
**Post date:** [July 15, 2007, 5:06am UTC](https://www.ruby-forum.com/t/passing-arguments-to-ruby-script/109456/1 "2007-07-15T05:06:56Z")

</div>

Hi,

I’m using ajax with ruby for my application, and need to send an  
argument to the ruby script for further action. I couldnt do it using  
the command line method, since the ruby script is being called from  
inside a JavaScript script. The following line of code calls the ruby  
script:

xmlHttp.open(“GET”,“ajaxhandler.rb”,true)

If I do something like:  
xmlHttp.open(“GET”,“ajaxhandler.rb” + myargument,true)  
then the script fails.

The PHP way to handle such cases is to add “?argument=argumentvalue”  
after the file name. And then within the PHP script you can further  
parse the values.

Is there anything similar in Ruby ? Or is there any other fix to this  
problem ?

Thanks,  
Gale

---

<div class="post-metadata">

**Author:** ![galecho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@galecho](https://www.ruby-forum.com/u/galecho)\
**Post date:** [July 15, 2007, 6:14am UTC](https://www.ruby-forum.com/t/passing-arguments-to-ruby-script/109456/2 "2007-07-15T06:14:57Z")

</div>

Gale CC wrote:

> If I do something like:  
> xmlHttp.open(“GET”,“ajaxhandler.rb” + myargument,true)  
> then the script fails.
> 
> The PHP way to handle such cases is to add “?argument=argumentvalue”  
> after the file name. And then within the PHP script you can further  
> parse the values.
> 
> Is there anything similar in Ruby ? Or is there any other fix to this  
> problem ?

Briefly: Use Ruby on Rails. It hides all this wiring and patching behind  
a  
slick interface, so you can spend time on your actual features.

Without RoR, your question here is the moral equivalent of an Assembler  
question on a C newsgroup. Don’t re-invent the wheel.

If you simply cannot, then raid its JS library, prototype.js, for  
high-level  
wrappers. There’s simply no reason to call xmlHttp yourself, when  
libraries  
like prototype.js have taken care of all the hairy asynchronicity and  
networking issues for you.

---

<div class="post-metadata">

**Author:** ![galecho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@galecho](https://www.ruby-forum.com/u/galecho)\
**Post date:** [July 15, 2007, 6:33am UTC](https://www.ruby-forum.com/t/passing-arguments-to-ruby-script/109456/3 "2007-07-15T06:33:36Z")

</div>

> If you simply cannot, then raid its JS library, prototype.js, for  
> high-level  
> wrappers. There’s simply no reason to call xmlHttp yourself, when  
> libraries  
> like prototype.js have taken care of all the hairy asynchronicity and  
> networking issues for you.

Firstly, I dont want to use Rails because I’m not writing a full fledged  
web app, but rather something with a web interface and Ruby just happens  
to be the scripting language.  
Secondly, I guess I didnt phrase my question properly. I just want to  
know a way to figure out how to “parse” and not “pass” arguments sent to  
a script. I know I can send arguments using  
“scriptname.rb?argument1=value1&argument2=value2”, I just want to know a  
way to parse those two values - argument1 and argument2 inside the  
script scriptname.rb. Is there a way around ?

Thanks,  
Gale

---

<div class="post-metadata">

**Author:** ![galecho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c57346/32.png) [@galecho](https://www.ruby-forum.com/u/galecho)\
**Post date:** [July 15, 2007, 7:43am UTC](https://www.ruby-forum.com/t/passing-arguments-to-ruby-script/109456/4 "2007-07-15T07:43:56Z")

</div>

Gale CC wrote:

> > If you simply cannot, then raid its JS library, prototype.js, for  
> > high-level  
> > wrappers. There’s simply no reason to call xmlHttp yourself, when  
> > libraries  
> > like prototype.js have taken care of all the hairy asynchronicity and  
> > networking issues for you.
> 
> Firstly, I dont want to use Rails because I’m not writing a full fledged  
> web app, but rather something with a web interface and Ruby just happens  
> to be the scripting language.  
> Secondly, I guess I didnt phrase my question properly. I just want to  
> know a way to figure out how to “parse” and not “pass” arguments sent to  
> a script. I know I can send arguments using  
> “scriptname.rb?argument1=value1&argument2=value2”, I just want to know a  
> way to parse those two values - argument1 and argument2 inside the  
> script scriptname.rb. Is there a way around ?
> 
> Thanks,  
> Gale

Nevermind I figured it out.  
I just need to access it using a cgi object- cgi.params[‘argument1’]
