# Ruby and URL Variables

**URL:** <https://www.ruby-forum.com/t/ruby-and-url-variables/133815>\
**Category:** Ruby\
**Created:** [April 3, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/ruby-and-url-variables/133815 "2008-04-03T22:29:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaussome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7bcc69/32.png) [@zaussome](https://www.ruby-forum.com/u/zaussome)\
**Post date:** [April 3, 2008, 10:29pm UTC](https://www.ruby-forum.com/t/ruby-and-url-variables/133815/1 "2008-04-03T22:29:31Z")

</div>

I’m quite new to Ruby and am wondering if there is a way to access what  
I called “URL variables” (not sure if that’s the proper name.) They were  
essentially GET variables, and PHP made it very easy to access with a  
global called $\_GET.

Is there an equivalent for Ruby? I’m trying to avoid using Rails, I  
don’t like it much.

For more clarification, if somebody visits a file called “test.rb” in  
their web browser with the full URL “test.rb?foo=bar,” how could I have  
the app print “bar,” or more specifically, the value of foo.

---

<div class="post-metadata">

**Author:** ![zaussome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7bcc69/32.png) [@zaussome](https://www.ruby-forum.com/u/zaussome)\
**Post date:** [April 3, 2008, 10:42pm UTC](https://www.ruby-forum.com/t/ruby-and-url-variables/133815/2 "2008-04-03T22:42:43Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Apr 3, 2008, at 10:29 PM, Devlin Zaussome wrote:

> I’m quite new to Ruby and am wondering if there is a way to access  
> what  
> I called “URL variables” (not sure if that’s the proper name.) They  
> were  
> essentially GET variables, and PHP made it very easy to access with a  
> global called $\_GET.

Those are called GET-Parameters :).

> Is there an equivalent for Ruby?

As Ruby is not built with web development in mind, it does not have  
such a thing.

But parameters are accessible through the CGI-Library. You can  
find an introduction here: (it is a bit dated, but it mostly fits)

[http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html](http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html)

> I’m trying to avoid using Rails, I don’t like it much.

There are other nice web frameworks in Ruby - try one of those.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkf1QOAACgkQJA/zY0IIRZb16gCff6ti0kUnok68xvsmwA2hqSFS  
6GAAnRrnke0CwZsXHoQH1ImzBtCladdn  
=7juI  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![zaussome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7bcc69/32.png) [@zaussome](https://www.ruby-forum.com/u/zaussome)\
**Post date:** [April 3, 2008, 10:51pm UTC](https://www.ruby-forum.com/t/ruby-and-url-variables/133815/3 "2008-04-03T22:51:50Z")

</div>

Florian G. wrote:

> > Is there an equivalent for Ruby?
> 
> As Ruby is not built with web development in mind, it does not have  
> such a thing.
> 
> But parameters are accessible through the CGI-Library. You can  
> find an introduction here: (it is a bit dated, but it mostly fits)
> 
> [Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html)

Thanks very much for that link, I’ve got it working now. 🙂
