Works in Webrick But Not Lighttpd
Posted by Vince Wadhwani on Oct 11, 2006
I was having this really strange issue where an RJS page was working on my local machine booting webrick but not on my Ubuntu server running Lighttpd. I booted webrick on my server and confirmed everything worked so the problem *had* to be with lighttpd. I upgraded from Dapper's standard 1.4.11 to the fresh 1.4.13 but it still didn't help.
Luckily, I got some help on the forums and from firebug. If you run into an issue like the one described above, I hope this helps you:
Using the firebug console, I was able to see the headers when I clicked through on my page. Here is a comparison:
WORKED (webrick)
Cache-Control: no-cache
Connection: close
Date: Tue, 10 Oct 2006 19:56:41 GMT
Content-Type: text/javascript; charset=UTF-8
Server: WEBrick/1.3.1 (Ruby/1.8.4/2005-12-24)
Content-Length: 2014
Set-Cookie: _session_id=5d3950e52b565ec95c26509d573f913f; path=/
DID NOT WORK (lighttpd)
Connection: close
Transfer-Encoding: chunked
38.909643Content-Type: text/javascript
Set-Cookie: _session_id=246ae40922c0fd45f1514aeb4bf790ae; path=/
Cache-Control: no-cache
Date: Tue, 10 Oct 2006 19:41:35 GMT
Server: lighttpd
See that 38.909643? Because it was sitting in front of the Content-Type: text/javascript the browser was not correctly interpreting the code as javascript. The 38.909643 was there because of a print statement in my code. Print, like warn, is a method of debugging ruby code. It can be used if you want to confirm a variable is correct for instance.
Anyway, because I had forgotten to take out that print statement lighttpd was incorrectly passing the Content-Type. I'm pretty sure this is a bug with lighttpd but I did not test it in Apache2. Still, I hope it saves others out there some grief.
You should avoid having ‘print’ in your ruby on rails code. ‘print’ prints to the standard output, if you are in an environment without a standard ouput, such as a webserver it won’t work (and may even cause problems). I encountered the same issue using Apache2.
I have taken to using ‘ruby-debug’ it is much better option than cluttering your code with prints.
adsfghcde@hotmail.com
I’m actually having another problem where something works in webrick but not lighttpd but this time it’s unrelated to a print statement:
http://www.ruby-forum.com/topic/85131
I’m starting to wonder if lighttpd is more trouble than it’s worth..
vince