Consider this CGI script:

#!ruby
require "cgi"
cgi = CGI.new("html4")
cgi.out {
  CGI.pretty(
    cgi.html {
     cgi.head { cgi.title{"Example"}+"<link rel=\"stylesheet\"
type=\"text/css\" href=\"example.css\">" } +
     cgi.body{"This should have a green background"}
    }
  )
}

with this example.css, both residing in the same directory:

body {
	background-color: #00ff00;
	}

it produces this html output:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
  <HEAD>
    <TITLE>
      Example
    </TITLE>
    <link rel="stylesheet" type="text/css" href="example.css">
  </HEAD>
  <BODY>
    This should have a green background
  </BODY>
</HTML>

Perfectly fine, it seems. The only problem is, that the background isn't
green, it's white (Firefox' default color, on my system).
However, if I save the html-source to a static example.html, put in the
same directory as my example.rb and open it in the browser, the css is
correctly applied and the background turns green.

It works if I put the css directly in the example.rb like this:

#!ruby
require "cgi"
cgi = CGI.new("html4")
cgi.out {
  CGI.pretty(
    cgi.html {
      cgi.head {cgi.title{"Example"}+
            cgi.style('type'=>'text/css'){File.read("./example.css")}} +

      cgi.body{"This should have a green background"}
    }
  )
}

But this way the css is not cacheable...

Where lies the problem in my script?

(FYI I use ruby 1.8.2 (2004-12-25) [i386-mswin32], Apache and Windows XP
Pro)

-- 
Posted via http://www.ruby-forum.com/.