ruby on rails link_to图片 [英] ruby on rails link_to an image
问题描述
我遇到以下问题:我有一个非常小的图片库,图片文件位于以下目录中
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>
如何解决这个问题?
有两个方法可以解决这个问题。
-
您必须在路径中指定assets文件夹。
link_to(image_tag(locale / thumbs / 001.jpg),
/assets/locale/big/spizzicaluna001.jpg)
-
使用图像路径允许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.
You must specify the assets folder in the path.
link_to( image_tag("locale/thumbs/001.jpg"), "/assets/locale/big/spizzicaluna001.jpg" )
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屋!