Javascript 使用jQuery变量添加rails图像_标记
我正在用jquery添加一个rails image_标记,并试图在image_标记中添加一个jQueryvariableJavascript 使用jQuery变量添加rails图像_标记,javascript,ruby-on-rails,Javascript,Ruby On Rails,我正在用jquery添加一个rails image_标记,并试图在image_标记中添加一个jQueryvariable var variable = 0; $(targetPlayerElement).html('<%= image_tag @users[variable].profile_picture var变量=0; $(targetPlayerElement).html(“您在这里混合了两种东西,var variable=0是javascript,如何将变量的内容存储为纯Ru
var variable = 0;
$(targetPlayerElement).html('<%= image_tag @users[variable].profile_picture
var变量=0;
$(targetPlayerElement).html(“您在这里混合了两种东西,var variable=0
是javascript,如何将变量的内容存储为纯Ruby,然后在图像标记中使用它
例如:
<div id="content"></div>
<% image = 'http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg' %>
<script>$('#content').html('<%= image_tag image %>')</script>
$('#content').html('')
什么是@users
?用户来自控制器users=User.limit(5.order)(“RANDOM()”)我认为这行不通,因为变量
是在计算
之后设置的。当我尝试将字符串隐式转换为整数错误时,我没有得到任何字符串隐式转换。@Gerry你是对的@jrocc尝试只使用ruby``$html(“”“``我同意首先使用compact
是有意义的。
<div id="content"></div>
<% image = 'http://placekitten.com.s3.amazonaws.com/homepage-samples/408/287.jpg' %>
<script>$('#content').html('<%= image_tag image %>')</script>