Reputation: 9415
I'm trying to wrap a link around an li in my rails app, and I thought the following would work:
<%= link_to project_path(remix) do %>
<li>
<div class="remix-list-image"><%=link_to image_tag(remix.default_image.image_path_url(:preview), :class=>"img-polaroid"), project_path(remix) %></div>
<div class="remix-list-title"><%=link_to remix.title, project_path(remix) %> by <%= link_to remix.author, user_path(remix.user) %></div>
</li>
<% end %>
But it's producing the following html:
<a href="/projects/206">
</a>
<li>
<a href="/projects/206"></a>
<div class="remix-list-image">
<a href="/projects/206"></a>
<a href="/projects/206"><img alt="Preview_2013-06-18_08.25.02" class="img-polaroid" src=""></a>
</div>
<div class="remix-list-title"><a href="/projects/206">Video Test Remix</a> by <a href="/users/tiff">tiff</a>
</div>
</li>
I expect it to do something like the following:
<a href ="/projects/206">
<li>...</li>
</a>
What am I doing wrong?
Upvotes: 3
Views: 3773
Reputation: 16888
Are you looking at the Inspector, or the actual generated code? If the former, it's probably what the browser is interpreting your HTML as, rather than what it actually is in the source code.
The reason it's wonky is because you can't put an li
into an anchor in that way; the only thing a ul
or ol
is allowed to contain is an li
. Change the code to this, and it should work:
<li>
<%= link_to project_path(remix) do %>
<div class="remix-list-image"><%=link_to image_tag(remix.default_image.image_path_url(:preview), :class=>"img-polaroid"), project_path(remix) %></div>
<div class="remix-list-title"><%=link_to remix.title, project_path(remix) %> by <%= link_to remix.author, user_path(remix.user) %></div>
<% end %>
</li>
Upvotes: 4