ruby on rails link_to图片 [英] ruby on rails link_to an image

查看:131
本文介绍了ruby on rails link_to图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下问题:我有一个非常小的图片库,图片文件位于以下目录中

  app / assets / images / locale / thumbs / 
app / assets / images / locale / big /

我必须创建一个超链接,作为内容具有拇指图像和目标 - 来自 app / assets / images / locale / big / 文件夹的更大版本:

 < a href =path-to-full-size-image-001.jpg> 
< img alt =第一张照片预览src =/ assets / locale / thumbs / 001.jpg/>
< / a>

我这样做是通过

  = link_to(image_tag(locale / thumbs / 001.jpg),locale / big / spizzicaluna001.jpg)

事实上,我已经为 link_to 的第二个参数尝试了很多变种,但收效甚微 - 无法找到更大的文件。 / p>

如何解决这个问题?

解决方案

有两个方法可以解决这个问题。


  1. 您必须在路径中指定assets文件夹。


    link_to(image_tag(locale / thumbs / 001.jpg),
    /assets/locale/big/spizzicaluna001.jpg)



  2. 使用图像路径允许rails找到正确的图像


    link_to(image_tag(locale / thumbs / 001.jpg),image_path(
    locale / big / spizzicaluna001.jpg))



更多我image_path上的nfo:



http: //apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_path


I'm facing the following problem: I have a very small image gallery with image files located in the following directories

 app/assets/images/locale/thumbs/
 app/assets/images/locale/big/

I have to create a hyperlink that as a content has a thumb image and as a target - its bigger version from app/assets/images/locale/big/ folder:

<a href="path-to-full-size-image-001.jpg">
 <img alt="first photo preview" src="/assets/locale/thumbs/001.jpg" />
</a>

I'm doing this by means of

= link_to(image_tag("locale/thumbs/001.jpg"),  "locale/big/spizzicaluna001.jpg") 

In fact I have tried many variants for the second argument of link_to but with little success - the bigger file can not be found.

How to resolve this issue?

解决方案

There are two approches to this issue.

  1. You must specify the assets folder in the path.

    link_to( image_tag("locale/thumbs/001.jpg"), "/assets/locale/big/spizzicaluna001.jpg" )

  2. Use an image path allowing rails to find the correct image

    link_to( image_tag("locale/thumbs/001.jpg"), image_path( "locale/big/spizzicaluna001.jpg") )

More info on image_path:

http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_path

这篇关于ruby on rails link_to图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆