Can't get basic CGI and Form submission working

I’m not a programmer, but like to use Ruby for writing simple programs,
mainly for helping with my day job (as a network engineer). My normal
method of coding is to take an example out a book (“The Pragmatic
Programmers Guide”, what else? :)) and tailor/expand it to to my needs.

I’ve just written a program which produces its results in HTML, for
convenient viewing. I’m feeling a little more ambitious now and would
like now to get a small amount of interaction using simple forms.
However, I’m not really getting past the first hurdle. I thought that
putting

"STUFF"

… would run the script indicated. Instead I get a ‘404’ “The
requested URL <path…> was not found on this server.”

I also tried

...

In fact, I tried this version first but it neither worked nor gave me
any errors. I know the script in question itself works because I can
run it from the command line (plus it is just creating a ‘Hello World!’
file) - which is to say I chmod 755 the file and started it with the
path to the Ruby bin.

I’m probably missing something really basic, and any advice would be
gratefully received.

thanks in advance

In message [email protected], Toby
Rodwell writes:

… would run the script indicated. Instead I get a ‘404’ “The
requested URL <path…> was not found on this server.”

The path you give must be the path within the web server’s view, not
the filesystem path. So, “/home/bob/src/test.rb” won’t work, for
instance. Typical would be to put the program in your server’s CGI
directory, and specify “/cgi-bin/test.rb”.

-s

unknown wrote:

The path you give must be the path within the web server’s view, not
the filesystem path. So, “/home/bob/src/test.rb” won’t work, for
instance. Typical would be to put the program in your server’s CGI
directory, and specify “/cgi-bin/test.rb”.

-s

Thanks ‘s’, that did the trick. I’ve now progressed one step to a new
error message: "405 - POST Method not allowed for the URL "
Anyone any ideas? I’m guessing either its another web server config
issue or I’m not using ‘POST’ correctly …

Thanks again!

unknown wrote:

Sounds like the web server isn’t allowing POSTs to that directory.
Try changing the form to a GET and see whether it works; if it does,
that’s the issue.

This has fairly little to do with Ruby per se, and a lot to do with
whatever web server you’re running.

-s

Makes sense - I’ll investigate the web-server settings.

thanks
Toby

In message [email protected], Toby
Rodwell writes:

Thanks ‘s’, that did the trick. I’ve now progressed one step to a new
error message: “405 - POST Method not allowed for the URL ”
Anyone any ideas? I’m guessing either its another web server config
issue or I’m not using ‘POST’ correctly …

Sounds like the web server isn’t allowing POSTs to that directory.
Try changing the form to a GET and see whether it works; if it does,
that’s the issue.

This has fairly little to do with Ruby per se, and a lot to do with
whatever web server you’re running.

-s

On May 14, 2007, at 3:35 AM, Peter S. wrote:

that’s the issue.

This has fairly little to do with Ruby per se, and a lot to do with
whatever web server you’re running.

-s

True, it isn’t directly a Ruby issue, but it is an issue directly
related to and important when dealing with many classes from the Ruby
standard library, and no small number of gems.
405 is a message like 404 Not Found. There’s a whole list of them.
Server error messages for http.
Make sure you’re using the right URI/URL.
Also, your script may be trying to write inside the CGI-BIN
directory. If it doesn’t have permissions for that, it won’t be able
to do that (this is not unusual) it should be writing to some other
location that is outside of executable space. A directory for read/
write only (a data store) or a database. You have to learn a bit
about where your web server puts things and what the host’s policies
are. Some are more free about things than others, but all have
individual quirks.
Your account or your script may just not have permissions to execute
the file. Or, the server admin doesn’t allow it or isn’t allowing
you. You’ll have to ask them.