【问题标题】:Use an image path from database as link_to使用数据库中的图像路径作为 link_to
【发布时间】:2017-04-07 13:45:13
【问题描述】:

我从数据库中的表格中提取了一张图片,然后我想将其制作成一个链接,以便查看者可以看到完整的文章。我已经看到理论上我可以使用以下内容,

<%= link_to image_tag('image/someimage.png') + "Some text", some_path %>

但在我的情况下,'image/someimage.png' 是

<%= image_tag coffeeshop.image_thumb_path %>

我尝试简单地将图像标签部分放入其中,因此它变为&lt;%= link_to image_tag('image_tag coffeeshop.image_thumb_path') + "Some text", some_path %&gt;,但这不起作用。有没有办法做到这一点?

【问题讨论】:

    标签: ruby-on-rails link-to


    【解决方案1】:
    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 %>
    

    【讨论】:

      猜你喜欢
      • 2013-05-31
      • 2014-04-16
      • 1970-01-01
      • 2019-07-27
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多