Newer
Older
about-Leaflet / hello.rb
@SugawaraMiyu SugawaraMiyu on 7 Feb 2025 756 bytes Update hello.rb
#!/usr/bin/env ruby
require 'cgi'

c = CGI.new
name = c["onamae"]

# Content-typeの出力(HTML形式)
print "Content-type: text/html; charset=utf-8\n\n"  # お約束

# HTMLの出力
print(<<EOF)
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hello!!!</title>
</head>
<body>
    <form method="POST" action="hello.rb">
        <p>あなたの名前: <input type="text" name="onamae"></p>
        <p><input type="submit" value="送信">
        <input type="reset" value="reset"></p>
    </form>
    
    <!-- 名前が入力された場合のみ表示 -->
    <h2>こんにちは#{name}さん!!</h2> if name && !name.empty?

</body> 
</html>
EOF