This is a card in Dave's Virtual Box of Cards.
Ruby CGI
Created: 2022-07-25
Make a directory listing:
#!/usr/bin/ruby
source_dir = 'foo/bar/'
web_path = '/my/foo/bar/'
puts "Content-Type: text/html"
puts ""
puts "<html><body>"
Dir.entries(source_dir).sort.each do |fname|
fpath = "#{web_path}#{fname}"
puts "<a href=\"#{fpath}\">#{fname}</a><br>"
end
puts "</body></html>"
And there’s a CGI module built right into the standard library:
But you don’t even need that for environment variables, which is why CGI is so dang sweet.