1
我想知道是否有一种方法可以动态地使用jQuery添加rails image_tag。在jQuery中添加rails image_tag
$(targetPlayerElement).html("<%= image_tag 'User.find_by_id(27).profile_picture'%>");
这就是我到目前为止所尝试的。
谢谢你的帮助。
我想知道是否有一种方法可以动态地使用jQuery添加rails image_tag。在jQuery中添加rails image_tag
$(targetPlayerElement).html("<%= image_tag 'User.find_by_id(27).profile_picture'%>");
这就是我到目前为止所尝试的。
谢谢你的帮助。
你可以尝试使用:
$(targetPlayerElement).html('<%= image_tag User.find_by_id(27).profile_picture %>');
那一定是这样的:
$(targetPlayerElement).html('<img src="src" alt="46" />')
如果您在控制台中得到一个Uncaught SyntaxError: missing) after argument list
错误,则是因为image_tag
是双引号里面,而src
的image_tag
也将用双引号括起来。
如果是字符串,则不需要引用User.find_by_id(27).profile_picture
的结果,将会被引用。
哪个版本的Rails?使用find
代替find_by_id
。
此外,使用单引号将image_tag
打印出来。
感谢您的帮助,它生成的HTML代码正确,但即时通讯语法错误,我无法弄清楚。 Uncaught SyntaxError:missing)在参数列表后 – jrocc
由于双引号内的双引号,我更新了答案。 –
它的工作非常感谢你! – jrocc