Rails Way to display if !blank?

Robert Head wrote:

<% if !foo.blank? %>   <div class="foo_class"><%= foo %></div> <% end %>

The elemental they mentioned in a previous message looks great. I have also found this helper useful.

# Will print the content in the given tag if the condition is true. If # no condition is provided then it will use the existance of real data # in the content value to determine if content should be printed def if_tag(tag_name, content, html_options={},condition=!content.blank?)    content_tag(tag_name, content, html_options) if condition end

I use would reproduce what you were trying to do with:

<%=if_tag('div', foo, :class=>'foo_class')%>


there is even more elegant solution using markaby. by default markaby rendering empty tags, but you would easily change its behaviour, look into builder.rb, search for tag! method and amend it to return nothing if passed block converted to string is empty. then all you need to write in in template is

div.foo_class 'foo'