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 />   if test == true<br />     icon = 'check.gif'<br />   else<br />     icon = 'x.gif'<br />   end<br />   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









On Tuesday, May 2
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.
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
On Tuesday, May 2
Good stuff. I recently did something similar. It's purely a stylistic preference, but you can shorten the method to:
def true_false(test)
image_tag(test ? 'check.gif' : 'x.gif')
end
On Tuesday, May 2
Ok. This must be an omen for me to change my style to the old C style if statement formats. (Someone else posted something similar about some php code the other day.
Anyhow... Glad you like, thanks for the hint back.