20seven

Devigner blog about development and design

Simple but True

This is so simple it’s almost not even worth posting, but, oh well.

I needed to convert true or false fields from the database to image icons in my views on mutliple pages today, so I wrote this tiny helper and dropped it into my application_helper.rb file.

def true_false(test)<br /> &#xA0;&#xA0;if test == true<br /> &#xA0;&#xA0;&#xA0;&#xA0;icon = 'check.gif'<br /> &#xA0;&#xA0;else<br /> &#xA0;&#xA0;&#xA0;&#xA0;icon = 'x.gif'<br /> &#xA0;&#xA0;end<br /> &#xA0;&#xA0;image_tag(icon)<br /> end

All it does is convert my tinyint fields from MySQL to image icons for a checkmark or an X and I can call it from anywhere since it’s in my application helper.

Cheers