ERROR NoMethodError: private method `gsub!' called

I have just upgraded to Ruby 1.8.7 and Rails 2.2.2. My previous project was at Ruby 1.8.6 and Rails 2.0.2. My platform is Windows and Webrick for development.

When I run Webrick, the server starts without error, the application runs, database connections work and I can click through the pages and display data. But it does not serve any stylesheets or javascript files. What's interesting is that images are displayed. In the log file, I get a 500 error after it attempts to retrieve a stylesheet or javascript. This occurs everytime.

Example of attempt to retrieve prototype.js (a 500 error):

I have just upgraded to Ruby 1.8.7 and Rails 2.2.2. My previous project was at Ruby 1.8.6 and Rails 2.0.2. My platform is Windows and Webrick for development.

When I run Webrick, the server starts without error, the application runs, database connections work and I can click through the pages and display data. But it does not serve any stylesheets or javascript files. What's interesting is that images are displayed. In the log file, I get a 500 error after it attempts to retrieve a stylesheet or javascript. This occurs everytime.

Example of attempt to retrieve prototype.js (a 500 error): ------------- 127.0.0.1 - - [17/Mar/2010:23:52:52 Eastern Daylight Time] "GET /javascripts/pro totype.js?1268882775 HTTP/1.1" 500 338 Referer -> /javascripts/prototype.js?1268882775 [2010-03-17 23:52:52] ERROR NoMethodError: private method `gsub!' called for #<Class:0x44ee480> -------------

If I type directly into my browser's address bar, "http://localhost:3001/javascripts/prototype.js?1268882775&quot;, I get the 500 error message as above. If I leave off "?1268882775", the browser asks me to download the JS file.

I created a new rails app, started the webrick server, and it also fails to run.

Any ideas what could be wrong? I'm stumped.

Thanks,

Chris

Chris, when you switched your app from 2.0.2 to 2.3.5, did you run 'rake rails:update' in the root of your project?

-Conrad

Chris, when you switched your app from 2.0.2 to 2.3.5, did you run 'rake rails:update' in the root of your project?

-Conrad

It was to 2.2.2 and, yes, I did run 'rake rails:update'. Not sure if it did anything. It didn't give any output and returned to the command prompt.

Since I was at an old rails version I tried to just upgrade to 2.1 with not luck and then upgraded to 2.2.2 to see if that would help. Same issue.

Thanks for the help.

Chris

Can you show us the rest of the error trace.

Colin

You can tell whether it changed anything by checking your current version against the version in your version control repository. If you are not using one (git for example) start by setting one up. When messing about upgrading rails and so on you need to be able to track what you have done, revert experimental changes, and so on. A day or two spent learning git will be recovered very quickly.

Colin

As much of the trace as I can get from my Windows command prompt. It doesn't log this to log/development.log. You'll see GET calls and then the 500 error followed by the "private method `gsub!'" error message repeatedly. Seems to affect all of the static files---stylesheets, javascripts, images. Sometimes it pulls images from my cache and if I refresh the page the image is missing again...

Colin Law wrote:

You can tell whether it changed anything by checking your current version against the version in your version control repository. If you are not using one (git for example) start by setting one up. When messing about upgrading rails and so on you need to be able to track what you have done, revert experimental changes, and so on. A day or two spent learning git will be recovered very quickly.

Colin

I use subversion. Not much changed after executing "rake rails:update" on my current project. I think it mainly changed the boot.rb file.

What is odd is that I even created a new rails app from scratch and it is also having the same problem serving up anything from the public folder---stylesheets, javascripts, images, etc... If I start webrick on this new app, it appears that the "new rails app" page loads with the images, but if I refresh, it immediately gives me the 500 errors on the static content.

I think I've worked through most of the other problems related to all the various plugins I'm using, but this issue still is puzzling why even a new rails app has the same problem.

Chris

Out of interest have you tried mongrel? script/server mongrel

Otherwise I am out of my depth I am afraid.

Colin

Out of interest have you tried mongrel? script/server mongrel

Otherwise I am out of my depth I am afraid.

Colin

Well, I executed "gem install mongrel", then "ruby script/server webrick" and everything is loading!! What a bad problem with webrick. My staging server is mongrel, but my production is phusion passenger (which is a breeze to setup). I hope Passenger will be kind when I make the next release to production!

I think it even cleared up an annoying "stack level too deep" error I was getting with webrick and not caching classes in development. Mongrel isn't complaining.

Thanks for your help!

Chris

Out of interest have you tried mongrel? script/server mongrel

Otherwise I am out of my depth I am afraid.

Colin

Well, I executed "gem install mongrel", then "ruby script/server webrick" and everything is loading!!

I presume you mean "ruby script/server mongrel"

Colin

Well, I executed "gem install mongrel", then "ruby script/server webrick" and everything is loading!!

I presume you mean "ruby script/server mongrel"

Colin

Yes... Sorry. Webrick still on the mind.

ruby script/server mongrel

Works!

Chris Mentch wrote:

Well, I executed "gem install mongrel", then "ruby script/server webrick" and everything is loading!!

I presume you mean "ruby script/server mongrel"

Colin

Yes... Sorry. Webrick still on the mind.

ruby script/server mongrel

Works!

To continue using Webrick, instead of switching to Mongrel, you can also just edit line 15 of lib/ruby/1.8/webrick/htmlutils.rb to read

      str = string ? string.to_s.dup : ""

The problem is that NotModified exception is getting passed to HTMLUtils::escape as a class, rather than a string (originally raised in HTTPServlet::DefaultFileHandler). Since the only things that can really be HTML escaped are strings, it should be safe to always convert the input to string.

I suspect that the potential performance penalty may prevent a solution like that from making it to the standard ruby library, but it's a simple workaround.

Alternatively, in the handle_file method of webrick's DispatchServlet (lib/webrick_server.rb in the rails gem), before it calls res.set_error with the exception, you could force the err.message to be a string, or even clear the message, since I think it's discarded anyway for NotModified.

Michael

Thank you very much! How very obvious to change that line. A pitty I haven't tried to change it that way.

But now everything works just fine. I had the nearly same problem with the same versions of Ruby and Rails but on Ubuntu. In my case stylesheets etc. were loaded after some reloading of the page.

Thank you again!

thx it works for me :slight_smile: