이것은 쿠키를 설정하는 방법으로 온라인에서 계속 볼 수있는 예입니다.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와 반대되는 것 또는 차이가 있는지를 설명하기를 원할 것인지 궁금합니다.
cgi.out("cookie" => [cookie]){""}
밖으로 당신의 헤더를 세척 할 수 있습니다 :
덕분에,
레위
은 조금 더 나는 cgi.out 무엇 cgi.header는 것의 대부분을 처리하는 것을 알아 냈다. 그래서 출력을 제어하는 것이 더 간결한 방법일까요? – Levi