【发布时间】:2009-04-12 13:19:46
【问题描述】:
这是我一直在网上看到的关于如何设置 cookie 的示例。
require "cgi"
cookie = CGI::Cookie.new("rubyweb", "CustID=123", "Part=ABC");
cgi = CGI.new("html3")
cgi.out( "cookie" => [cookie] ){
cgi.html{
"\nHTML content here"
}
}
我尝试过这样做,它设置了 cookie,然后出现了一个空白页面。
#!/usr/local/bin/ruby
require 'cgi'
load 'inc_game.cgi'
cgi = CGI.new
cookie = CGI::Cookie.new("rubyweb", "CustID=123", "Part=ABC");
cgi.out( "cookie" => [cookie] ){""}
#see if game submit buttons pressed
doIt = cgi['play']
puts "Content-type: text/html\n\n"
play = Game.new
#welcome
if doIt == ''
puts play.displayGreeting
end
#choose weapon
play.playGame
if doIt == 'Play'
move = cgi['weapon']
human = play.humanMove(move)
computer = play.ComputerMove
print human
print computer
result = play.results(human,computer)
play.displayResults(result)
end
所以我的问题首先是,我错过了什么/做错了什么?其次,我想知道是否有人想解释 .out 与 .header 相比有什么作用,或者是否有区别?
谢谢,
李维斯
【问题讨论】:
-
通过阅读更多内容,我发现 cgi.out 可以处理 cgi.header 的大部分内容。那么它只是一种更简洁的控制输出的方式吗?