Rails and the pngfix.js script
I've been doing some Ruby on Rails development in the last couple of weeks. I worked out my page design before hand, tested it in different browsers, and then encoded it into rhtml
for the default application view so it would apply to all pages, and very well it seemed to work too. The problem came when I tested the finished application - I was using the pngfix.js script to fix the transparency of an image in my banner for IE, in my initial design this all worked fine, when it was running in rails it didn't seem to work.
After viewing the generated source the problem was obvious, I had converted my static link to the image_tag helper in the application layout so that it would work on the live site and also in my development environment (different root paths) and this helper adds a random key to the end of the image src to stop the browser caching it, so it now looked like image.png?1148154649
. The problem was the pngfix.js script looks only at the last three characters of the image name and so now it was ignoring the image. I could have hardcoded the script (it's only the one image, after all), I could even have learned how to stop Rails adding the random gunk (it's not like I mind people caching the image in this case) but I could see how to fix the javascript straight away so I did that instead. Find this line:
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
And replace it with:
if (imgName.indexOf('.PNG') > 0)
There's a small chance the script will now incorrectly identify images which have the string .png
embedded in their names for some reason, but I figure the chance of that is small.
Print article | This entry was posted by robertc on 29/06/06 at 11:41:45 pm . Follow any responses to this post through RSS 2.0. |