You could actually create an helper method like this
In your application_helper.rb:
def conditional_link(options={}, &block)
unless options.delete(:hide_link)
concat content_tag(:a, capture(&block), options)
else
concat capture(&block)
end
end
And in your view:
<% conditional_link(:hide_link => url.nil?, :href => "/hello" ) do %>
<%= image_tag(image_url) %>
<h1><%= title %></h1>
<h2><%= subtitle %></h2>
<% end %>
Assuming that your url.nil?
does work properly by returning a boolean
You can of course pass more options to your link, for example a class or id:
<% conditional_link(:hide_link => url.nil?, :href => "/hello", :class => "myclass", :id => "myid" ) do %>
<%= image_tag(image_url) %>
<h1><%= title %></h1>
<h2><%= subtitle %></h2>
<% end %>