简体   繁体   English

ReactJs中的Rails image_tag帮助器

[英]Rails image_tag helper in ReactJs

I use this way of getting my methods inside my js, such as current_user etc. I need to get the image_tag inside my js. 我使用这种方式在我的js中获取方法,例如current_user等。我需要在我的js中获取image_tag Why? 为什么? I store the images inside the asset pipeline so once I upload to Heroku, it adds a weird string at the end of the image filename ie: foo.png becomes foo-hkjghhgasb87ysbsb.png . 我将图像存储在资产管道中,因此一旦上传到Heroku,它就会在图像文件名的末尾添加一个奇怪的字符串,即: foo.png变为foo-hkjghhgasb87ysbsb.png

So inside an html.erb file: 因此,在html.erb文件中:

<div id="foo" data-editBtn="<%= image_tag("icons/ic_mode_edit_black_24px.svg", height: '24', width: '24') %>"></div>

js.jsx file: js.jsx文件:

var el = document.getElementById('foo');
{el.dataset.editBtn}

Is there a way to get the helper method to work in react or...how to add an image that is in the asset pipeline? 有没有一种方法可以使助手方法起作用,或者...如何添加资产管道中的图像?

Guess I'll answer this. 猜猜我会回答这个。 Based on the heroku docs about images in the asset pipeline, I would: 根据关于资产管道中图像的heroku文档 ,我将:

html.erb: html.erb:

<div id="foo" data-btn="<%= asset_path('logo.png') %>"></div>

js.jsx: js.jsx:

var el = document.getElementById('foo');
<div><img src={el.dataset.btn}></img></div>

No I got the image in the js with worrying about the generated finderprint. 不,我担心担心生成的finderprint在js中得到图像。

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

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