不用 RoR 寫 Ruby ..


剛在閒逛..終於給我發現了不用 Framework (RoR) 寫 Ruby 的方法 ..
真的是感謝上天 = = 太高興了…寫下了這個簡單的例子..還是很有 Perl 味道..

參考 : http://willh.org/~cfc/wiki/index.php/Programming_Ruby_Ruby_and_the_Web
資料 : http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html
資料 : http://rubycgi.org/cgi_explanation/index.htm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/local/bin/ruby

require 'cgi'
cgi = CGI.new

print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"

print "<html>";
print "<body>";

(1..10).each do|i|
print "<li>Number : #{i}</li>";
end

print "<hr />";

print "<form action='ruby.cgi' method='post'>";
print "<input type='text' name='keyword' value='' />";
print "<input type='submit' value='測試' />";
print "</form>";

if cgi['keyword'] != ""
print "<div>";
print cgi['keyword'];
print "</div>";
end

print "</body>";
print "</html>"