如何使用Cloudinary输出带有转换的URL作为字符串? [英] How can I use Cloudinary to output a url with transformation as a string?
问题描述
在开始我之前,我可能会说这可能是错误的做法。我想做的是使用 data-
属性将包含转换的网址传递给JS。
I'll preface this by saying that may be approaching this incorrectly. What I'm trying to do is pass the url w/transformation into JS using a data-
attribute.
目前,我正在使用以下代码生成图像标签:
Currently, I'm using the following to generate the image tag:
= cl_image_tag(image.asset.filename.to_s, transformation: "scroller", :"data-medium" => image.asset.filename.to_s)
产生的内容:
<img src="http://res.cloudinary.com/bucket/image/upload/t_scroller/v1373070863/s1ufy3nygii85ytoeent.jpg" data-medium="s1ufy3nygii85ytoeent.jpg">
我想要做的就是将其输出(使用 t_medium
我已设置的命名过渡):
What I'd like to be able to do is have it output this (Utilizing the t_medium
named transition I've set up):
<img src="http://res.cloudinary.com/bucket/image/upload/t_scroller/v1373070863/s1ufy3nygii85ytoeent.jpg" data-medium="http://res.cloudinary.com/bucket/image/upload/t_medium/v1373070863/s1ufy3nygii85ytoeent.jpg">
当前 cl_image_tag
正在繁重工作通过使用正确配置的URL生成图像标签。很好,但是我似乎找不到任何有关如何将配置的URL作为没有图像标签的字符串输出的文档(用作 data-medium
属性)。我可以手动配置URL,但是我想知道是否有更好的方法?
Currently the cl_image_tag
is doing the heavy lifting by generating an image tag with the correctly configured URL. This is great, however I can't seem to find any documentation on how to output a configured URL as a string without the image tag (to use as the data-medium
attribute). I could manually configure the URL, but I was wondering if there was a better way?
推荐答案
您可以使用cloudinary_url帮助器进行操作生成没有图片标签的网址。例如:
You can use the cloudinary_url helper to generate the URL without the image tag. For example:
cloudinary_url(image.asset.filename.to_s, transformation: "medium")
如zeantsoi所说,如果您使用的是CarrierWave,还可以将上传器本身作为参数传递:
As zeantsoi said, if you are using CarrierWave, you can also pass the uploader itself as a parameter:
cloudinary_url(image.asset, transformation: "medium")
这篇关于如何使用Cloudinary输出带有转换的URL作为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!