これは、Cookieの設定方法としてオンラインで見続ける例です。RubyでCGIクッキーはどのように動作しますか?
require "cgi"
cookie = CGI::Cookie.new("rubyweb", "CustID=123", "Part=ABC");
cgi = CGI.new("html3")
cgi.out("cookie" => [cookie]){
cgi.html{
"\nHTML content here"
}
}
このようにして、クッキーを設定して空白のページを表示します。
#!/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
私の最初の質問は間違っていますか?第二に、誰かが.headerとは対照的に.outが何をしているのか、あるいは違いがあるのかを説明したいと思っているのでしょうか?
おかげで、私はこの行信じる
レヴィ
もう少し読んでから、私はcgi.outは何cgi.headerが希望の多くを扱うことが分かりました。それでは、出力を制御するより簡潔な方法ですか? – Levi