Sunday, January 21, 2007

Suppressing link_to_if text when condition is false

The rails link_to_if function is great for, well, creating a link if and only if a condition is true. The prototype is

options = {},
html_options = {},
*parameters_for_method_reference, &block)

Unfortunately, the default behavior is to put the link text on the page (with no link) if the condition is false. To rid yourself of the pesky text, so that nothing shows up if the condition is false, just add an empty block…

link_to_if(false, "Don't show me",a_fancy_url) {}


Anonymous said...

Thank you!

Anonymous said...

works great in firefox 3.01
IE7 prints an empty box space
I love IE7 ... not!