当我在轨道上用标签包围它时,为什么我的图像会消失?

时间:2022-11-24 09:08:52

Initially, this code:

最初,这段代码:

<%= image_tag(thumbnail(drawing.image_url), class: "drawing")%>

which resulted in:

结果导致:

<img class="drawing" src="http://res.cloudinary.com/brandonliu/image/upload/t_thumb_large/v1430498900/00001.jpg" alt="00001">

worked just fine, but as soon as I switched it to a link_to:

工作得很好,但一旦我将其切换到link_to:

<%= link_to image_tag(thumbnail(drawing.image_url), class: "drawing"), drawing %>

the image stopped displaying. The image in fact disappears anytime I surround it with a hyperlink tag, does anyone know why?

图像停止显示。事实上,当我用超链接标签环绕它时,图像就会消失,有谁知道为什么?

EDIT: I don't think the problem is with the rails syntax, because simply doing

编辑:我不认为问题是与rails语法,因为干脆做

<a><%= image_tag(thumbnail(drawing.image_url), class: "drawing")%></a>

still does not allow the image to display

仍然不允许显示图像

2 个解决方案

#1


Try pass a block with image_tag to the link_to helper:

尝试将带有image_tag的块传递给link_to帮助器:

<%= link_to some_path_here do %>
  <%= image_tag(thumbnail(drawing.image_url), class: "drawing") %>
<% end %>

From documentation:

You can use a block as well if your link target is hard to fit into the name parameter.

如果您的链接目标很难适合name参数,也可以使用块。

#2


image_tag renders the string

image_tag呈现字符串

<img src="...">

which is the image tag. To make a link, you need the path to the image, not a rendering of a tag.

这是图片标签。要创建链接,您需要图像的路径,而不是标记的呈现。

Try this

<%= link_to image_path(thumbnail(drawing.image_url)) %>

#1


Try pass a block with image_tag to the link_to helper:

尝试将带有image_tag的块传递给link_to帮助器:

<%= link_to some_path_here do %>
  <%= image_tag(thumbnail(drawing.image_url), class: "drawing") %>
<% end %>

From documentation:

You can use a block as well if your link target is hard to fit into the name parameter.

如果您的链接目标很难适合name参数,也可以使用块。

#2


image_tag renders the string

image_tag呈现字符串

<img src="...">

which is the image tag. To make a link, you need the path to the image, not a rendering of a tag.

这是图片标签。要创建链接,您需要图像的路径,而不是标记的呈现。

Try this

<%= link_to image_path(thumbnail(drawing.image_url)) %>