Absolute beginner - simple question!

<%= link_to_if(!comment.website.nil?, h comment.name, comment.website) %> says: <%= h comment.body %>

This should do the trick. Look at the API* for the usage of link_to_if and link_to_unless.

I guess you are having problems with the <%= if ...%>. The <%= (with the equal sign) means that the block will be evaluated, converted to string and added to the view. The <% (without equal sign) means that the block will be evaluated and nothing is going to be added to the view. Basically:

<%= h "Hello world!" %> outputs "Hello world!" <% h "Hello world!" %> outputs "" (nothing).

Also, DON'T forget to escape your strings that come from your models. It is very easy to do so: add the "h" in front of them. This protects you against several types of attack.

* http://api.rubyonrails.org/

Felipe

Try removing the "h" from there...

Try removing the "h" from there...

On Dec 22, 12:37 am, Richard Brashaw <rails-mailing-l...@andreas-

Ah, brilliant - still it always shows a link, but now there are no errors, hopefully I can work that out for myself.

If anyone else ever finds this, I think that using comment.website.length > 0 as a test might be better than !comment.website.nil? as that always makes a link.

Yes - the empty string is not nil. You may find blank? appropriate: an
empty string is blank, as is nil

Fred