takaoueda
11/23/2004 6:48:00 AM
The following is a simple example of how Erb can be used
to integrate HTML, Tk, and Ruby.
I put this program in the \apache\cgi-bin\ directory of Apache
1.3, and tested by directly calling http://localhost/cgi-bin
/erbtest.rb with etscape 4.75 and IE 6.0 Win98SE with the
newest Ruby 1.8.2-14RC9 executable for Windows. I experienced:
..Apache 2.0 does not work with Win98SE.
..Both IE and Netscape do not display files of the mime type
x-httpd-eruby. Therefore, I had to give up the use of
so-called embedded Erb with the file extension .rhtml and
the addition of AddType application and Action application
to the Apache conf file.
..Tcl/Tk with Erb failed with Apache with a message of unfound
"tcltklib" with the older Ruby 1.8.1 for Windows.
..The "malformed header" error occurs if the second line is
missing.
..The comment on the first line is displayed on the Web page.
A solution to this problem was given by Carlos in another
message.
..If the Tk.mainloop is exited without printing anything,
"The document has no data" error message is given by Netscape.
..In order to avoid the Dos windows being stuck or instantly
closed during debugging, I opened Tool of Windows Explorer and
edited File Types so that, in my case, files of the file types
..rb and .erb should be respectively opened with command.com /k
"E:\ruby\bin\ruby.exe" %1 and command.com /k E:\ruby\bin\erb.bat"
%1 and used Windows Explorers or editors to run the programs.
Test program (erbtest.erb)
#! E:/ruby182/ruby/bin/erb.bat
<%print "Content-type: text/html\r\n\r\n"%>
<html><body>
<form method=post enctype=application/x-www-form-urlencoded>
<hr><h1>A Form: </h1>
<textarea cols =50 name=get_text rows=5></textarea>
<br><input type=submit></form>
<%con_length=ENV['CONTENT_LENGTH'].to_i%>
<%=content=STDIN.read(con_length)%>
<%require 'tk'%>
<%if content =~ /tk\+test/%>
<%TkButton.new {%>
<% text "Ok"%>
<% command proc { p "Thank you"; exit }%>
<%pack { side 'left'; padx 20; pady; 20 }%>
<%}%>
<%Tk.mainloop%>
<%end%>
</body></html>