Write webpages in Ruby without Rails? - Newb Question

R

rgossen

I am a programming newb and I just bought the book "Software
Engineering for Internet Applications," and I need a server to go
through the labs. Unfortunately, the extent of my server experience
is using script/server in Rails. To do these labs, I need to write
webpages in Ruby without Rails (or any framework), but I am not sure
exactly how to go about it.

I started to use the Apache 1.3 webserver that comes with os x and
attempted to install eruby. That doesn't seem to be working. I am
thinking there has to be an easier way. Is there a way for me to use
Mongrel or Webrick outside of Rails? I initially installed everything
using the Hivelogic instructions.
 
J

Jeremy Woertink

rgossen said:
I am a programming newb and I just bought the book "Software
Engineering for Internet Applications," and I need a server to go
through the labs. Unfortunately, the extent of my server experience
is using script/server in Rails. To do these labs, I need to write
webpages in Ruby without Rails (or any framework), but I am not sure
exactly how to go about it.

I started to use the Apache 1.3 webserver that comes with os x and
attempted to install eruby. That doesn't seem to be working. I am
thinking there has to be an easier way. Is there a way for me to use
Mongrel or Webrick outside of Rails? I initially installed everything
using the Hivelogic instructions.

well, you can write HTML like a string, then have the output be an HTML
file. So,


html_file = File.new("C:\web_pages\index.html", "w+")

html_file.write("<html>\n<head>\n<title>OMG THIS IS GOING TO TAKE A LONG
TIME</title>\n</head>\n</html>")

html_file.close


Hopefully someone has a better idea :)

Good luck

~Jeremy
 
C

Colin Summers

This is really a question for the rails-talk list, but since I am
right now in rails...

I would create a rails application and a default controller and index
action. Then you can just write Ruby inside a <% %> pair in the
index.rhtml file.

I am sure you'll get a dozen responses about how to set it up simpler,
but that's the way I know you can get it to work from where you are.

--Colin
 
T

Todd Benson

I am a programming newb and I just bought the book "Software
Engineering for Internet Applications," and I need a server to go
through the labs. Unfortunately, the extent of my server experience
is using script/server in Rails. To do these labs, I need to write
webpages in Ruby without Rails (or any framework), but I am not sure
exactly how to go about it.

I started to use the Apache 1.3 webserver that comes with os x and
attempted to install eruby. That doesn't seem to be working. I am
thinking there has to be an easier way. Is there a way for me to use
Mongrel or Webrick outside of Rails? I initially installed everything
using the Hivelogic instructions.

I haven't played with Ruby and web outside of frameworks (Rails,
Camping, etc.), but you can use Apache with mod_ruby I think. Your
files will probably have to take on the eruby syntax of <% %>
encapsulating code tags, which would be similar to other interactive
web code (ala CodeFusion and others).

As far as I can tell, Mongrel knows how to feed a web server( like
Apache), but is not necessarily a complete web server itself.
Somebody correct me if I'm wrong, because I can't seem to find any
straight example of somebody just using Mongrel with Ruby by
themselves to serve pages!

thx,
Todd
 
D

dusty

I am a programming newb and I just bought the book "Software
Engineering for Internet Applications," and I need a server to go
through the labs. Unfortunately, the extent of my server experience
is using script/server in Rails. To do these labs, I need to write
webpages in Ruby without Rails (or any framework), but I am not sure
exactly how to go about it.

I started to use the Apache 1.3 webserver that comes with os x and
attempted to install eruby. That doesn't seem to be working. I am
thinking there has to be an easier way. Is there a way for me to use
Mongrel or Webrick outside of Rails? I initially installed everything
using the Hivelogic instructions.

Check out webrick. Here is a simple script that will do a directory
listing on wherever you run it. Just open up your browser to port
2000.

Now, to get it to actually output html content-types and all, will
require some more work. But, perhaps this will get you started.

#!/bin/env ruby
require 'webrick'
include WEBrick

s = HTTPServer.new(
:port => 2000,
:DocumentRoot => Dir::pwd
)

trap("INT"){ s.shutdown }
s.start
 
N

Nathan Grant

I would recommend the "serve" gem

http://wiseheartdesign.com/2007/9/25/introducing-serve/

It makes it simple to code and serve webpages with ruby.

But there are lots of options for generating HTML code using ruby,
check rubyforge.org for gems like "markaby" or "xx".

You can serve page with Mongrel like this:

require 'rubygems'
gem 'mongrel'
require 'mongrel'

HOST = '0.0.0.0'
PORT = 999

config = Mongrel::Configurator.new :host => HOST, :port => PORT do
listener do
uri "/", :handler => Mongrel::DirHandler.new(Dir.pwd)
end

trap("INT") { stop }
run
end

puts "Mongrel running on #{HOST}:#{PORT} with docroot #{Dir.pwd}"
config.join
 
J

Jeremy Hinegardner

As far as I can tell, Mongrel knows how to feed a web server( like
Apache), but is not necessarily a complete web server itself.
Somebody correct me if I'm wrong, because I can't seem to find any
straight example of somebody just using Mongrel with Ruby by
themselves to serve pages!

You might want to give heel a try, that's pretty much what it is, mongrel with
some mime-type sugar and nice directory listings.

% sudo gem install heel
% heel
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** heel running at http://127.0.0.1:4331 with document root /home/jeremy/proj
** Use Ctrl-C to stop.
** Launching your browser...
127.0.0.1 - - [07/Nov/2007:00:58:17 MST] "GET / HTTP/1.1" 200 46615
127.0.0.1 - - [07/Nov/2007:00:58:17 MST] "GET /icons/folder.png HTTP/1.1" 200 537
127.0.0.1 - - [07/Nov/2007:00:58:17 MST] "GET /icons/application.png HTTP/1.1" 200 464

enjoy,

-jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top