This is the example I keep seeing online as how to set cookies.
require 'cgi' cookie = CGI::Cookie.new('rubyweb', 'CustID=123', 'Part=ABC'); cgi = CGI.new('html3') cgi.out( 'cookie' => [cookie] ){ cgi.html{ '\nHTML content here' } }
I tried doing it this way and it sets the cookie and then comes up with a blank page.
#!/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
So my question first would be, what am I missing/doing wrong? Secondly I am wondering if anyone would want to explain what .out does as opposed to .header or if there is a difference?
Thanks,
Levi
I believe this line:
Is flushing your headers out.
Upon running the code bare in my TTY,
was emitted, and ‘Content-Length: 0’ ( generated by the empty string in out{} ) is possibly telling the browser you’re done.
Would be preferable for sending headers.
Opting for a ‘do processing’ – ‘then think about output’ model might help.