在jQuery中添加rails图像_标记
我想知道是否有一种方法可以使用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
$(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代码,但我发现了一个语法错误,我无法理解。未捕获的语法错误:缺少)参数列表后由于双引号中有双引号,我重新更新了答案。