new

CGI.new(tag_maker) { block }
CGI.new(options_hash = {}) { block }
Class Public methods

Create a new CGI instance.

tag_maker

This is the same as using the options_hash form with the value { :tag_maker => tag_maker } Note that it is recommended to use the options_hash form, since it also allows you specify the charset you will accept.

options_hash

A Hash that recognizes two options:

:accept_charset

specifies encoding of received query string. If omitted, @@accept_charset is used. If the encoding is not valid, a CGI::InvalidEncoding will be raised.

Example. Suppose @@accept_charset is âUTF-8â

when not specified:

cgi=CGI.new      # @accept_charset # => "UTF-8"

when specified as âEUC-JPâ:

cgi=CGI.new(:accept_charset => "EUC-JP") # => "EUC-JP"
:tag_maker

String that specifies which version of the HTML generation methods to use. If not specified, no HTML generation methods will be loaded.

The following values are supported:

âhtml3â

HTML 3.x

âhtml4â

HTML 4.0

âhtml4Trâ

HTML 4.0 Transitional

âhtml4Frâ

HTML 4.0 with Framesets

âhtml5â

HTML 5

block

If provided, the block is called when an invalid encoding is encountered. For example:

encoding_errors={}
cgi=CGI.new(:accept_charset=>"EUC-JP") do |name,value|
  encoding_errors[name] = value
end

Finally, if the CGI object is not created in a standard CGI call environment (that is, it can't locate REQUEST_METHOD in its environment), then it will run in âofflineâ mode. In this mode, it reads its parameters from the command line or (failing that) from standard input. Otherwise, cookies and other parameters are parsed automatically from the standard CGI locations, which varies according to the REQUEST_METHOD.

doc_ruby_on_rails
2015-04-01 03:20:52
Comments
Leave a Comment

Please login to continue.