I want to show a post author's name; <% @post.author.name %>
works unless author is nil. So I either use unless @post.author.nil?
or add a author_name method that checks for nil as in <% @post.author_name %>
. The latter I try to avoid.
The problem is that I may need to add/remove words depending on whether there is a value or not. For instance, "Posted on 1/2/3 by " would be the content if I simply display nil. I need to remove the " by " if author is nil.