简体   繁体   English

Rails-将html标签添加到image_tag

[英]Rails - Adding html tag to a image_tag

I have an image_tag in rails. 我在rails中有一个image_tag。 I have a jquery plugin that requires me to add a tag data-elem=pinchzoomer to enable touch zoom. 我有一个jquery插件,要求我添加一个标签data-elem=pinchzoomer来启用触摸缩放。 How do I add this to the below? 如何将其添加到下面?

image_tag(@listing.image.url, class: "rsTmb img-responsive")

Like so: 像这样:

image_tag(@listing.image.url, class: "rsTmb img-responsive", data: {elem: 'pinchzoomer')

For data elements, just add the key 'data' to the hash you're passing to the helper method, and use the bit after "data-" to be the keys to the hash. 对于数据元素,只需将键“ data”添加到您要传递给辅助方法的哈希中,然后使用“ data-”之后的位作为哈希键即可。 So, if you wanted to have data-foo='fred' data-bar='barney', you'd add: 因此,如果您想使用data-foo ='fred'data-bar ='barney',则可以添加:

data: {foo: 'fred', bar: 'barney'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM