Flowdock
link_to_if(condition, name, options = {}, html_options = {}, *parameters_for_method_reference, &block) public

Create a link tag of the given name using an URL created by the set of options, if condition is true, in which case only the name is returned (or the given block is yielded, if one exists).

Show source
Register or log in to add new notes.
October 30, 2009
2 thanks

Outputs name even if condition is false

Please note that if the condition is false, link_to_if will still output the name given as a plain text (as documented above). If you want nothing printed at all, you’ll have to stay with the old and trusty:

link_to "Login", ... if @current_user.nil?
October 30, 2009
0 thanks

Outputs name even if condition is false

Please note that if the condition is false, link_to_if will still output the name given as a plain text (as documented above). If you want nothing printed at all, you’ll have to stay with the old and trusty:

link_to "Login", ... if @current_user.nil?