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)
Which produces this:
<img src="http://res.cloudinary.com/bucket/image/upload/t_scroller/v1373070863/s1ufy3nygii85ytoeent.jpg" data-medium="s1ufy3nygii85ytoeent.jpg">
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">
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?
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")
As zeantsoi said, if you are using CarrierWave, you can also pass the uploader itself as a parameter:
cloudinary_url(image.asset, transformation: "medium")
On top of Tal Lev-Ami's answer:
If you need to call cloudinary_url outside of a view (for instance in a serializer model for an api), you have 2 options:
helper.cloudinary_url
Cloudinary::Utils.cloudinary_url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With