Forum: Ruby Passing arguments to ruby script

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
20f6bbf518ce68b66fdc2c9126e91601?d=identicon&s=25 Gale CC (galecho)
on 2007-07-15 05:06
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
1040215636f35f752ce36af2cdd61458?d=identicon&s=25 Phlip (Guest)
on 2007-07-15 06:14
(Received via mailing list)
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.
20f6bbf518ce68b66fdc2c9126e91601?d=identicon&s=25 Gale CC (galecho)
on 2007-07-15 06:33
> 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
20f6bbf518ce68b66fdc2c9126e91601?d=identicon&s=25 Gale CC (galecho)
on 2007-07-15 07:43
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']
This topic is locked and can not be replied to.