# Newbie - Problem Two - Ruby and Form Variables, re-loading l

**URL:** <https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575>\
**Category:** Ruby\
**Created:** [January 4, 2006, 11:05pm UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575 "2006-01-04T23:05:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 4, 2006, 11:05pm UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575/1 "2006-01-04T23:05:03Z")

</div>

I am attempting to copy a PHP project I did in Ruby.

I basically have a search form / web page, which looks for matching  
records and displays them prior to the search box form.

I reload the page with

I then use the isset function to test whether any records have been  
displayed and skip the display and go straight to the form. I know  
this could have been achieved with javascript, but that was a no no.

I have discovered require cgi and it sems to give me all the info I  
need, but how do I replicate the form button action re-loading the page  
with all the variables in tact.

Thanks

Richard

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575/2 "2006-01-05T17:44:30Z")

</div>

On Thu, Jan 05, 2006 at 07:03:34AM +0900, removed\_email\_address@domain.invalid  
wrote:

> 

If I remember my PHP correctly, $\_SERVER[‘PHP\_SELF’] is simply the  
name of the currently executing file. The Ruby equivalent is  
**FILE**.

regards,  
Ed

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 5, 2006, 11:45pm UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575/3 "2006-01-05T23:45:53Z")

</div>

Thanks for the replies, and yes PHP\_SELF is the name of the running  
current page.

I am sorry to be stupid, but how do I get the form action to execute  
basename( **FILE** ) as I did with:

\<FORM action="\<?php print $\_SERVER['PHP\_SELF'];?\>" method="POST"

Thanks again

Richard

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 6, 2006, 1:25am UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575/4 "2006-01-06T01:25:06Z")

</div>

basename() is a PHP function, not a Ruby one.

~ ryan ~

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575/5 "2006-01-05T17:44:47Z")

</div>

Actually, you’ll also need to call basename(). So,

basename($\_SERVER[‘PHP\_SELF’] ) == **FILE**

~ ryan ~

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 6, 2006, 2:28am UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575/6 "2006-01-06T02:28:10Z")

</div>

On Jan 5, 2006, at 6:22 PM, J. Ryan S. wrote:

> basename() is a PHP function, not a Ruby one.

## $ ri -T File::basename --------------------------------------------------------- File::basename File.basename(file\_name [, suffix] ) -\> base\_name

```
  Returns the last component of the filename given in file_name,
  which must be formed using forward slashes (``/'') regardless of
  the separator used on the local file system. If suffix is given
  and present at the end of file_name, it is removed.

     File.basename("/home/gumby/work/ruby.rb") #=>

```

“ruby.rb”  
File.basename("/home/gumby/work/ruby.rb", “.rb”) #=\> “ruby”

James Edward G. II

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 6, 2006, 3:52am UTC](https://www.ruby-forum.com/t/newbie-problem-two-ruby-and-form-variables-re-loading-l/89575/7 "2006-01-06T03:52:15Z")

</div>

Thanks James. 🙂

~ ryan ~
