2013-07-14 27 views
3

我想包在我的Rails应用程序围绕李的链接,我想下​​面将工作:包装LINK_TO周围Rails的内容

​​3210

但它产生下面的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="https://stackoverflow.com/users/tiff">tiff</a> 
     </div> 
</li> 

我希望它这样做如下:

<a href ="/projects/206"> 
<li>...</li> 
</a> 

我在做什么错?

+0

可能重复的[如何将链接\ _to围绕一些html ruby​​代码?](http://stackoverflow.com/questions/1086360/how- do-i-wrap-link-to-around-some-html-ruby-code) – givanse

回答

2

您是否正在查看Inspector或实际生成的代码?如果是前者,可能是浏览器将HTML解释为,而不是源代码中的实际内容。

它是不可靠的原因是因为你不能把li放入一个锚点, ulol被允许包含的唯一东西是li。更改代码到这,它应该工作:

<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> 
+0

感谢您的帮助!我看着检查员,而不是来源(这似乎是正确的)。 – scientiffic

+0

有趣...似乎在链接中嵌套一个div是不可能的,除了html-5之外...很高兴知道! – scientiffic