【问题标题】:Rails, turning an image into a linkRails,将图像变成链接
【发布时间】:2013-04-21 16:11:35
【问题描述】:

我想把我的图片变成一个链接。但是怎么做?我阅读了不同的答案,但没有任何效果。

 <%= link_to image_tag(article.images.first.image.url, :alt => article.title) unless 
      article.images.first.nil? %> 

我使用此链接按标题引用文章。

<%= link_to(article) do %><h2><%= article.title %></h2><% end %>
This works!  the path.     But i want the same path "article" with the image.

【问题讨论】:

    标签: ruby-on-rails image hyperlink


    【解决方案1】:

    也许你可以做到这一点?在 link_to 之外进行检查

    【讨论】:

      【解决方案2】:

      这应该可行:

      <%= link_to image_tag(article.images.first.image.url, :alt => article.title) unless 
        article.images.first.nil?, article %>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-03
        • 2012-04-02
        • 2016-10-06
        • 2011-12-22
        • 2015-01-09
        • 2012-04-14
        • 1970-01-01
        • 2012-07-13
        相关资源
        最近更新 更多