Simple CGI example using ruby

require 'cgi'
 
cgi = CGI.new('html4')
 
env = ""
ENV.each_pair {|k,v|
        env += "#{k} : #{v}<br>\n"
}
 
 
cgi.out {
        cgi.html {
                cgi.head { cgi.title { __FILE__ }  } +
                cgi.body {
                        cgi.h1 { 'Welcome to ruby cgi' } +
                        "using #{__FILE__}" + cgi.br +
                        "Time now is #{Time.now}" + cgi.br +
                        "ENV type : #{env}" + cgi.br +
                        cgi.form() {
                                cgi.table {
                                        cgi.tr {
                                                cgi.td { "Name : " } + cgi.td { cgi.text_field('name','',80)  }
                                        } +
                                        cgi.tr {
                                                cgi.td { "Select:" } + cgi.td { cgi.submit }
                                        }
                                }
                        }
 
                }
        }
}

ruby_cgi.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0