Most rails tag helpers accept a block, which means you can use do to make your life easier. Here I use a block with link_to :
<%= link_to root_url do %> <%= image_tag "background.jpg" %> <% end %>
In this case, link_to expects the next parameter to be the path, and the block will emit what binds the binding to.
In general, I try to stick to one tag helper in the rule of each line, unless it is super trivial, so prefer this technique when the line is otherwise full. The advantage of this method is that the tags are on different lines, errors are easier to identify.
If you need other options, add them as usual. For example, I will add the css class:
<%= link_to root_url, :class => 'imagelink' do %> ...
IAmNaN
source share