post icon

RubyProf error “can’t convert Fixnum into String”

I recently maxxxxed out my memory limit on my regular dreamhost account at work causing 500 errors all over the place. This is now forcing me to start learning how to cache, and trace my apps for memory and performance. I also switched to PS with 300mb burstable to around 700mb. That should help out for now. Anyway, back to finding out which requests are drinking redbull… I installed the ruby-prof gem to find out. I ran a request with the param key added to the end of the url and wham! Errors? WTF? I copied the code right out of “Advanced Rails Recipes” correctly, and checked it 10 times? So what’s the error? “can’t convert Fixnum into String”? Well it seems that the printer class is trying to convert a number to a string, which just won’t happen. It was pretty obvious what was happening:

response.body << printer.print("", 0)

Right there! It’s trying to append the request body to the printer class with a integer passed as a hash. I haven’t looked at the ruby-prof code but the class doesn’t like that. So I just put quotes around it.

response.body << printer.print("", '0')

Then it worked out fine! Hope that helps someone out cause I spent about 2 hours searching for the problem.

No comments yet.

Leave a comment