Forum: Ruby Can't get basic CGI and Form submission working

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.
Toby R. (Guest)
on 2007-05-13 22:13
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
<form method="post" action="<path_to_ruby_script>">
  "STUFF"
     <input type ="submit" />
   </form>

... would run the script indicated.  Instead I get a '404' "The
requested URL <path...> was not found on this server."

I also tried
<form target="<path_to_ruby_script>"> ...
    <input type ="submit" />
   </form>

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
unknown (Guest)
on 2007-05-13 22:20
(Received via mailing list)
In message <removed_email_address@domain.invalid>, 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
Toby R. (Guest)
on 2007-05-13 22:28
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 <path>"
Anyone any ideas?  I'm guessing either its another web server config
issue or I'm not using 'POST' correctly ...

Thanks again!
unknown (Guest)
on 2007-05-13 22:36
(Received via mailing list)
In message <removed_email_address@domain.invalid>, 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 <path>"
>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
Toby R. (Guest)
on 2007-05-13 22:49
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
John J. (Guest)
on 2007-05-14 02:31
(Received via mailing list)
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.
This topic is locked and can not be replied to.