# Super simple serving of ruby pages

**URL:** <https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376>\
**Category:** Ruby\
**Created:** [September 20, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376 "2006-09-20T18:01:07Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 3:44am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/21 "2006-09-21T03:44:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 5:06am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/22 "2006-09-21T05:06:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 5:38am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/23 "2006-09-21T05:38:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 9:16am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/24 "2006-09-21T09:16:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 5:49am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/25 "2006-09-21T05:49:19Z")

</div>

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](http://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?

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/26 "2006-09-21T13:41:29Z")

</div>

This works fine:

eRuby: The Erb Alternative to Embedded Ruby in HTML  
[http://www.hiveminds.co.uk/node/3105](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

> **[RUBYCORNER.COM](https://www.rubycorner.com/)**
>
> RUBYCORNER.COM - Contact us for any business inquiries

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/27 "2006-09-21T17:07:58Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/28 "2006-09-21T18:18:33Z")

</div>

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

> [http://jamesbritt.com/code/wb\_erb.tgz](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

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 5:58pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/29 "2006-09-21T17:58:30Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/30 "2006-09-21T18:42:39Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 21, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/31 "2006-09-21T18:34:35Z")

</div>

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](http://foo.bar.com) port: 3000 application: dispatcher: class: StandardDispatcher mapfile: mapfile.cnf

## mapfile.cnf:

## 🗺 /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

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 28, 2006, 4:12am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/32 "2006-09-28T04:12:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 28, 2006, 4:18am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/33 "2006-09-28T04:18:37Z")

</div>

Jonathan D. wrote:

> how do i access the script output?

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

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 28, 2006, 6:51am UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/34 "2006-09-28T06:51:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [September 30, 2006, 2:26pm UTC](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376/35 "2006-09-30T14:26:14Z")

</div>

-----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](http://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](http://enigmail.mozdev.org)

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

[Previous page](https://www.ruby-forum.com/t/super-simple-serving-of-ruby-pages/69376.md?page=1)
