I'll try and pay you back at least some of the effort by addressing one of your TODOs. From your code:
# Windows only. TODO: figure out
# how to do the same thing on Mac and 'nix boxen.
Thread.new {
# Wait a bit for the server to start, then launch a Web browser
# to show the default page
sleep( 5 )
warn `start http://127.0.0.1:#{PORT}`
}
On Mac OS X, replace the word "start" with "open" and it will work.
Thanks, Jan. That was easy. Now .rhtml files render correctly.
Is there a way to tell it to execute .rb files rather than treat them
as simple text files?
Jan Svitok wrote:
> > Yes, I tried that. Unfortunately there is no documentation on the
> > webrick site on how to use ERBHandler. I have this in a ruby script
> > which does start up the Webrick server. However, while it serves HTML
> > files fine, it treats RHTML files as binaries and RB files as just
> > plain text. Here's my code:
>
> require 'webrick'
> include WEBrick
+ module WEBrick
+ module HTTPServlet
+ FileHandler.add_handler("rb", CGIHandler)
+ end
+ end
Now it starts .rb for me, although I'm not able to write any good cgi
right now maybe it's because I'm on windows...
Doesn't work for me. With even the simplest .rb file it gives me the
following error:
ERROR Premature end of script headers:
This is a classic CGI header error, caused by the absence of a recognizable
emitted header like:
print "Content-type: text/html\r\n\r\n"
As the first text emitted by the script.
Remember, if you can get the server to read the filetype and treat it as a
well-behaved source, and if you can get the Ruby scripts to emit the
expected header information, your server requirements become much simpler
to meet.
Got it. That works, thanks, Paul, and Jan, for your patience with my
ignorance.
It seems like I am at the same level as your daughter [although a whole
9 years older] and am trying to do the same thing you are. I could not
get anything working from what I gathered in this thread, but it seems
you have. Can you tell me what you ended up doing so I can do that too?
Got it. That works, thanks, Paul, and Jan, for your patience with my
ignorance.
It seems like I am at the same level as your daughter [although a whole
9 years older] and am trying to do the same thing you are. I could not
get anything working from what I gathered in this thread, but it seems
you have. Can you tell me what you ended up doing so I can do that too?
It's very simple, really. Apache requires that executable pages (pages that
have to be processed by an interpreter like Ruby) by placed in a special
directory. The default for this is usually /sitedirectry/cgi-bin.
Write an ordinary Ruby script, but make sure the first thing it prints is a
CGI header, like this:
print "Content-type: text/html\r\n\r\n"
After this first line, just output HTML, as in my prior example, and the
page will appear to all intents and purposes as though it contains the text
it is printing. Therefore your Ruby code decides what the page content is,
and it is obviously dynamic.
A Ruby interpreter must be installed on the server machine. Apart from that,
it should work without any fuss.
A Ruby interpreter must be installed on the server machine. Apart from
that,
it should work without any fuss.
ahh, well, thats probably my problem. i'm using the cheapest server i
could find (canaca.com), which obviousely has no support for ruby. i was
hoping there was some shortcut way i could use ruby on my website
without having to change servers. is there some way to do that, or is it
totally hopeless?
A Ruby interpreter must be installed on the server machine. Apart from
that,
it should work without any fuss.
ahh, well, thats probably my problem. i'm using the cheapest server i
could find (canaca.com), which obviousely has no support for ruby. i was
hoping there was some shortcut way i could use ruby on my website
without having to change servers. is there some way to do that, or is it
totally hopeless?
I didn't realize this was an offsite, commercial server. Many traditional
servers stay away from anything relatively new, to avoid instabilities.
Some commercial webservers allow you to install your own binaries. All you
have to do is find out what kind of processor and OS are in use, just as
you would for your home computer in choosing a binary. Then drop the
appropriate binary into /usr/bin or another suitable location, and you are
good to go.
But without this option or one like it, your instinct is correct -- you
wouldn't be able to run Ruby.
ahh, well, thats probably my problem. i'm using the cheapest server i
could find (canaca.com), which obviousely has no support for ruby. i was
hoping there was some shortcut way i could use ruby on my website
without having to change servers. is there some way to do that, or is it
totally hopeless?
Serve (part) of your website from your PC over which you have control?
If it's a personal website or to display some experiments, this should
be sufficient.
Thanks a lot. I didn't get it working. I put erb.cgi and a .htaccess in
/var/www/cgi-bin/ as directed in http://www.hiveminds.co.uk/node/3105
but I can't find out what kind of OS the server is using, and i cannot
create/edit files or directories in /bin or /usr/bin
at this point, it looks to me like i should give up trying to use ruby
on that server.
Thanks a lot. I didn't get it working. I put erb.cgi and a .htaccess in
/var/www/cgi-bin/ as directed in http://www.hiveminds.co.uk/node/3105
but I can't find out what kind of OS the server is using, and i cannot
create/edit files or directories in /bin or /usr/bin
Will any CGI script work in the /var/www/cgi-bin directory, for example one
that relies on "sh" or Perl? If so, put your own CGI script
in /var/www/cgi-bin that reveals things about the OS.
···
-------------------------------------
#!/bin/sh
echo -e "Content-type: text/html\r\n\r\n"
data=`set`
echo "<html><body><pre>$data</pre></body></html>"
-------------------------------------
Don't leave this script in place, just use it temporarily to find out what's
going on.
at this point, it looks to me like i should give up trying to use ruby
on that server.
Use the above script and change:
data=`whereis ruby`
Thanks again for your help.
Just some ideas, and your conclusion may be correct.
nevermind, I was able to try it but i just got an error message
What error message? For most typical errors, it's because you put the script
in a place where it cannot be executed. Also, in some cases the script has
to be given executable permissions.