0

I am writing a cgi script to pull the contents of a .txt file in the cgi-bin directory into the body of an html file and can't seem to figure it out.

eruby seems to be a solution, but I can't tell if it's to be used with Rails or not and the documentation is lacking for a newbie.

Here's what I've got:

#!/usr/local/bin/ruby
# SCRIPT hello_world.cgi
# CREATOR: Ryan Clark
puts "Content-type: text/html"
puts

#This line left intentionally blank

puts <<HTML
<!DOCTYPE html>
<html>
<head>
<title>Oliver Twist</title>
<style type ="text/css">
body {
background-color:#335;
color:#fff;
font-family:Helvetica,Arial,Verana,sans-serif;
font-size:12px;}
h1 {color:#c00}
</style>
</head>
<body>
<% File.open("oliver_twist.txt").each { |line| puts line } %>
</body>
</html>
HTML
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Taywin
0

If you are going to do it in Rails, you don't need to use CGI script to do because you can open and read files on Rails using File class. This script seems to create & render a HTML page for you using 'puts'.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.