Super simple serving of ruby pages

Bil K. wrote:

FWIW, I have the brain of an 8yr old in when it comes
to web-aps, and I managed to write a /couple/ Camping aps
the other evening.

Fascinating. I’ve looked at Camping but haven’t really
grasped it yet.

I’m not a web guy. I do it slowly and painfully.

I also have the brain of an eight year old. I keep it
in a jar on my desk.

Hal

zerohalo wrote:

Ruby code into rhtml files, but without Rails. I don’t really want a
online, and I’m no expert on web applications.
I’ve an example of this that’s ~100 lines of code, if you’re interested.

Maps URLs to classes and templates and renders them, using erb and
Webrick.


James B.

“A principle or axiom is of no value without the rules for applying it.”

  • Len Bullard

On Sep 20, 2006, at 8:05 PM, James B. wrote:

complicated
write a ruby script that generates an rhtml file, but then how do I
Maps URLs to classes and templates and renders them, using erb and
Webrick.


James B.

I’d be interested in seeing that James.

Thanks
-Ezra

Jonathan D. wrote:

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.

Paul L. wrote:

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?

This works fine:

eRuby: The Erb Alternative to Embedded Ruby in HTML
http://www.hiveminds.co.uk/node/3105

It is extremly easy to setup, I have tried this solution in 2 shared
hosting services without a problem.


Aníbal Rojas

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 again for your help.

On Sep 21, 2006, at 10:58 AM, James B. wrote:

http://jamesbritt.com/code/wb_erb.tgz

Fairly simple, few features, demos a few concepts.

Interesting. Thanks for sharing.

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.

Hope that helps.

James Edward G. II

Ezra Z. wrote:

On Sep 20, 2006, at 8:05 PM, James B. wrote:

I’d be interested in seeing that James.

Here ya go!

http://jamesbritt.com/code/wb_erb.tgz

Fairly simple, few features, demos a few concepts.


James B.

“Simplicity of the language is not what matters, but
simplicity of use.”

  • Richard A. O’Keefe in squeak-dev mailing list

Jonathan D. wrote:

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 “

$data


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.

On Thu, 21 Sep 2006, James B. wrote:

ERb looks like the ticket, but there’s a missing link (for me). I can
write a ruby script that generates an rhtml file, but then how do I
serve that rhtml file without a framework like
Rails/Nitro/Camping/etc.? Probably the answer is with Webrick somehow,
but I’m missing the connection. I can’t find a simple tutorial anywhere
online, and I’m no expert on web applications.

I’ve an example of this that’s ~100 lines of code, if you’re interested.

Maps URLs to classes and templates and renders them, using erb and Webrick.

I’d like to see it, just because I might find it educational.

I’ve also been wondering if framework support for this sort of thing,
but
very simple to setup, would be useful to people?

Something akin to this:

app.rb

require ‘iowa’

Iowa.run

app.cnf

socket:
hostname: foo.bar.com
port: 3000
application:
dispatcher:
class: StandardDispatcher
mapfile: mapfile.cnf

mapfile.cnf:

:map:
/index.html: Index
/form.html: Myform
/response.html: Myresponse

If one had an index.rhtml, myform.rhtml, and myresponse.rhtml, they
would
be mapped to classes Index, Myform, and Myresponse, and requests for the
urls above would go to the class in question and be rendered as an erb
template.

You’d run it with:

ruby app.rb -r webrick
or
ruby app.rb -r mongrel

No other code or config necessary to serve those rhtml files. Would
anyone use this ability (as I personally would not). Worth my time to
make the above work?

Kirk haines

Paul L. wrote:

Don’t leave this script in place, just use it temporarily to find out
what’s
going on.

how do i access the script output?

Jonathan D. wrote:

how do i access the script output?

nevermind, I was able to try it but i just got an error message

Jonathan D. wrote:

Jonathan D. wrote:

how do i access the script output?

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.

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

Jonathan D. wrote:

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.

David V.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFHmIwy6MhrS8astoRAg4fAJ91NJYACa7LhlQhq4XaCUfIDDM+1QCdHW+e
ux5wCukpPCM6L7pHYk95d0M=
=PhPZ
-----END PGP SIGNATURE-----