这是我一直在网上看到的如何设置 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 相比做什么,或者是否有区别?
谢谢,
列维