- Ruby - Home
- Ruby - Overview
- Ruby - Environment Setup
- Ruby - Syntax
- Ruby - Classes and Objects
- Ruby - Variables
- Ruby - Operators
- Ruby - Comments
- Ruby - if...else
- Ruby - Loops
- Ruby - Methods
- Ruby - Blocks
- Ruby - Modules
- Ruby - Strings
- Ruby - Arrays
- Ruby - Hashes
- Ruby - Date & Time
- Ruby - Ranges
- Ruby - Iterators
- Ruby - File I/O
- Ruby - Exceptions
- Ruby Advanced Topics
- Ruby - Object Oriented
- Ruby - Regular Expressions
- Ruby - Database Access
- Ruby - Web Applications
- Ruby - Sending Email
- Ruby - Socket Programming
- Ruby - Ruby/XML, XSLT
- Ruby - Web Services
- Ruby - Tk Guide
- Ruby - Ruby/LDAP Tutorial
- Ruby - Multithreading
- Ruby - Built-in Functions
- Ruby - Predefined Variables
- Ruby - Predefined Constants
- Ruby - Associated Tools
- Ruby Useful Resources
- Ruby - Quick Guide
- Ruby - Cheatsheet
- Ruby - Useful Resources
- Ruby - Discussion
- Ruby - Ruby on Rails Tutorial
Selected Reading
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 −
main.rb
require "cgi"
cgi = CGI.new("html4")
cgi.out {
cgi.html {
cgi.head { "\n"+cgi.title{"This Is a Test"} } +
cgi.body { "\n"+
cgi.form {"\n"+
cgi.hr +
cgi.h1 { "A Form: " } + "\n"+
cgi.textarea("get_text") +"\n"+
cgi.br +
cgi.submit
}
}
}
}
Output
Content-Type: text/html Content-Length: 337 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><HTML><HEAD> <TITLE>This Is a Test</TITLE></HEAD><BODY> <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded"> <HR><H1>A Form: </H1> <TEXTAREA NAME="get_text" COLS="70" ROWS="10"></TEXTAREA> <BR><INPUT TYPE="submit"></FORM></BODY></HTML>
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 |
ruby_web_applications.htm
Advertisements