Ruby - CGI Useful Methods


CGI Class Methods

CGI Instance Methods

HTML Generation Methods

You can create any HTML tag by using the corresponding HTML tag name along with any CGI instance. For example −

Live Demo

require "cgi"
cgi ="html4")
cgi.out {
   cgi.html {
      cgi.head { "\n"+cgi.title{"This Is a Test"} } +
      cgi.body { "\n"+
         cgi.form {"\n"+
            cgi.h1 { "A Form: " } + "\n"+
            cgi.textarea("get_text") +"\n"+

CGI Object Attributes

You can access any of the following attributes using a CGI instance −

Attribute Returned Value
accept Acceptable MIME type
accept_charset Acceptable character set
accept_encoding Acceptable encoding
accept_language Acceptable language
auth_type Authentication type
raw_cookie Cookie data (raw string)
content_length Content length
content_type Content type
From Client e-mail address
gateway_interface CGI version string
path_info Extra path
path_translated Converted extra path
Query_string Query string
referer Previously accessed URL
remote_addr Client host address
remote_host Client hostname
remote_ident Client name
remote_user Authenticated user
request_method Request method (GET, POST, etc.)
script_name Program name
server_name Server name
server_port Server port
server_protocol Server protocol
server_software Server software
user_agent User agent


E-Books Store