在jQuery中添加rails图像_标记

在jQuery中添加rails图像_标记,jquery,ruby-on-rails,Jquery,Ruby On Rails,我想知道是否有一种方法可以使用jQuery动态添加rails图像_标记 $(targetPlayerElement).html("<%= image_tag 'User.find_by_id(27).profile_picture'%>"); $(targetPlayerElement).html(“”); 这就是我到目前为止所尝试的 谢谢您的帮助。您可以尝试以下方法: $(targetPlayerElement).html('<%= image_tag User.find

我想知道是否有一种方法可以使用jQuery动态添加rails图像_标记

$(targetPlayerElement).html("<%= image_tag 'User.find_by_id(27).profile_picture'%>");
$(targetPlayerElement).html(“”);
这就是我到目前为止所尝试的

谢谢您的帮助。

您可以尝试以下方法:

$(targetPlayerElement).html('<%= image_tag User.find_by_id(27).profile_picture %>');
$(targetPlayerElement.html(“”);
这看起来一定像:

$(targetPlayerElement).html('<img src="src" alt="46" />')
$(targetPlayerElement).html(“”)
如果您在控制台中得到一个
Uncaught SyntaxError:missing)after参数列表
错误,那么这是因为
image\u标记
在双引号内,而
image\u标记
src
也将在双引号内

无需引用用户的
结果。按\u id查找\u(27)。如果是字符串,则已引用profile\u picture

哪个版本的Rails?使用
find
代替
find\u by\u id


此外,请使用单引号将打印的内容括起来。

感谢您的帮助,它正确生成了html代码,但我发现了一个语法错误,我无法理解。未捕获的语法错误:缺少)参数列表后由于双引号中有双引号,我重新更新了答案。