Archive for the ‘Ruby’ Category

PNG fix for MSIE now “Rails compatible” (howto)

Friday, August 10th, 2007

PNG transparency doesn’t work in Internet Explorer 5.5 and 6.0. Fortunately there is a fix from Twin Helix, which essentially a little piece of java script that makes PNGs work on MSIE version 5.5 and 6.0.There used to be a problem with the Rails image_tag because it adds parameters to the URL and the fix-script didn’t handle that. But this has now been fixed in version 1.0 RC5 preview 2.

Here’s a guide on how to make it work in Ruby on Rails.

1) Download the IEPNGFix v1.0 RC5 Preview 2 (iepngfix.zip) file from http://www.twinhelix.com/test/ and extract.
2) Create a directory called “iepngfix” in your rails /public/images directory and place the file blank.gif there
3) Place iepngfix.htc in the /public/javascripts/ directory
4) Add this line to your CSS:

5) Open the /javascripts/iepngfix.htc file and change the line that says

(line 15) to:

That’s it.

Troubleshooting: Make sure that the height and width parameters are not missing from your IMG tags.

Keeping track of Ruby gems in a Rails project

Monday, June 11th, 2007

On a project I’m working on were are two developers. To keep track of the gems needed, we had a file in the root rails dir called GEMS.txt with a list of gems. Then I thought: verifying if I had the right gems installed is a repetitive task the computer should do for me. So I converted the text file to a YAML file, GEMS.yml, that looked something like this:

# Required gems
#
# Version example: version 0.7.5 or higher: ~>0.7.5
# Version example: exactly version 0.7.5: =0.7.5
-
  name: diff-lcs
-
  name: ZenTest
-
  name: RSpec
  version: =1.0.5

This means that you need any version of “diff-lcs” and “ZenTest” and exactly version 1.0.5 of RSpec. You would probably have more gems in there, but I’ve kept the list short for this blog post. Let’s say that another developer has added a new gem to GEMS.yml or changed the required version. Now you simply run “rake check_for_gems”:

$ rake check_for_gems
Gem found: diff-lcs 1.1.2
Gem found: ZenTest 3.4.2

2 of 3 required gems found.
Warning: Gem not found: RSpec ~>1.0.5

Either you don’t have the gem installed at all or you don’t have the correct version. So you install the correct version of the gem and now when you run “rake check_for_gems”, you get “3 of 3 required gems found.”

This is the source of the rake task: You can copy paste and save as lib/tasks/check_for_gems.rake

It’s just a simple tool, but it scratched an itch and was quickly made. Ruby is not only great for web applications on Rails, but also for small scripts like this.

The new RSpec format - testing/spec’ing in Ruby

Sunday, May 27th, 2007

The RSpec API has been changed. So some of the documentation on RSpec syntax is now obsolete, including Dave Astel’s cheat sheet.

For instance this doesn’t work in the newest version:

I got an error message saying “undefined method `should_raise’”. It should be changed into:

I looked for documentation of these changes on the RSpec website. They are apparently not that easy to find. Pelle sent me this link to a page in the RDoc that describes the built in Expression Matchers and has examples. I haven’t found a super clear description of what “Expression Matchers” are, but they seem to be what goes after “should” or “should_not”.