使用数据库中的图像路径作为 link_to
Use an image path from database as link_to
我在 table 中从数据库中提取了一张图片,然后我想将其制作成 link 以便查看者可以看到完整的文章。我已经看到理论上我可以使用下面的内容,
<%= link_to image_tag('image/someimage.png') + "Some text", some_path %>
但在我的例子中 'image/someimage.png' 是
<%= image_tag coffeeshop.image_thumb_path %>
我试过简单地放入图片标签部分,所以它变成了 <%= link_to image_tag('image_tag coffeeshop.image_thumb_path') + "Some text", some_path %>
但这不起作用。有办法吗?
link_to(body, url, html_options = {})
您的 link_to
中的第一个参数将被解释为标签的主体,然后是您的 url
,但是如果您想在 link_to
中添加更多内容,您可以打开再关闭,里面的都这样解释:
<a href="#">
...
</a>
所以你可以试试:
<%= link_to some_path do %>
<%= image_tag coffeeshop.image_thumb_path %>
<% end %>
我在 table 中从数据库中提取了一张图片,然后我想将其制作成 link 以便查看者可以看到完整的文章。我已经看到理论上我可以使用下面的内容,
<%= link_to image_tag('image/someimage.png') + "Some text", some_path %>
但在我的例子中 'image/someimage.png' 是
<%= image_tag coffeeshop.image_thumb_path %>
我试过简单地放入图片标签部分,所以它变成了 <%= link_to image_tag('image_tag coffeeshop.image_thumb_path') + "Some text", some_path %>
但这不起作用。有办法吗?
link_to(body, url, html_options = {})
您的 link_to
中的第一个参数将被解释为标签的主体,然后是您的 url
,但是如果您想在 link_to
中添加更多内容,您可以打开再关闭,里面的都这样解释:
<a href="#">
...
</a>
所以你可以试试:
<%= link_to some_path do %>
<%= image_tag coffeeshop.image_thumb_path %>
<% end %>