From: Jim Menard Date: 2000-11-02T22:40:01+09:00 Subject: [ruby-talk:5989] Re: html, forms, ruby and apache Johann Spies writes: > What I want to do learn is how to use a browser like netscape to > handle database queries with ruby and Postgresql as backend. I was > also considering php as an alternative because one can embed it in an > html-document. Here is some cut-and-paste help. I don't cover installing PostgreSQL or installing mod_ruby or eruby here. Here's what I put in my httpd.conf file: ================================================================ # Problem: for some reason, mod_ruby.so has the library name "liberuby.so.0.1" # compiled in. I want to use "liberuby.so.0.1.2" instead. # # solution: Must create link in /usr/local/lib from liberuby.so.0.1 to # liberuby.so.0.1.2. LoadModule ruby_module /usr/lib/apache/mod_ruby.so AddModuler ruby-script .rb AddType application/x-httpd-ruby .rb # mod_ruby's eruby support AddType application/x-httpd-eruby .rhtml ================================================================ Here's an example eruby .rhtml file that hits the database (thanks to Dave Thomas for posting bits of Chapter 14 from his book). ================================================================ Ruby and PostgreSQL Test
<%
require 'postgres'

# Get dbname, username, and password from somewhere. No, you can't have
# mine :-)
conn = PGconn.connect('localhost', 5432, '', '', dbname, username, password)
csr = conn.exec("select * from sometable")
csr.fields.each { | column_name |
    print "#{column_name}\t"
}
print "\n"
csr.result.each { | row |
    row.each { | column |
	print "#{column}\t"
    }
    print "\n"
}
%>
================================================================ Jim -- Jim Menard jimm@io.com http://www.io.com/~jimm/ BeOS developer #1283 "What's a Superbowl? Does it save the city from ruin and destruction ON TOP OF containing some part of a complete breakfast?" -- J. on alt.fan.tom-servo