From: takaoueda@... Date: 2004-11-27T06:37:56+09:00 Subject: Re: Ruby+Tk+HTML Example We can also use class CGI within an Erb program. #! E:/ruby182/ruby/bin/erb.bat <%print "Content-type: text/html\r\n\r\n"%>

A Form:


<% require 'cgi'%> <%cgi = CGI.new%> <%content=cgi['get_text']%> <%if content =~ /tk\s*test/%> <%require 'tk'%> <% message = TkVariable.new%> <% "padx 20; pady 20"%> <% txt=TkText.new.pack%> <% txt.insert('end', content)%> <% TkLabel.new {%> <%text 'Enter a message:'%> <%pack {ph}%> <%}%> <% entry = TkEntry.new{%> <%textvariable message%> <%}%> <% entry.pack%> <% TkButton.new {%> <%text 'Send'%> <% command proc {p message.value; exit}%> <% pack { ph }%> <%}%> <%Tk.mainloop%> <%end%> Usually <%= aString%> is preferred to <%print aString%> in an Erb program, since the latter does not always follow the order of instructions of the program. However, in this example, when I changed the second line into <%="Content-type: text/html\r\n\r\n"%>, a puzzling thing happened. The first page containing the form is displayed all right. But when the server sends back a message "All right", Apache produced the error message '"bad header= "All right"'