我在页面上定义了一些动态图像,如下所示:
<%= image_tag(@recipe.image.url(:fixed), :class => 'recipe_image_show') %>
我正在寻找一种使用此代码定义og:image的方法。下面显示的og:description代码可以正常运行:
<meta property="og:description" content= "<%= @recipe.description %>" />
但是,如果我使用下面的代码,那么它就不会起作用:
<meta property="og:image" content='<%= image_tag(@recipe.image.url(:fixed), :class => 'recipe_image_show') %>'/>
有什么建议么?我意识到我在这里使用了单引号,但是由于某种原因使用了双引号导致页面忽略meta标签的'/>'部分并将其显示为文本。
根据聊天讨论,OP将图像托管在S3上。
因此,定义meta
标签如下:
<meta property="og:image" content='<%= @recipe.image.url(:fixed) %>'/>
将被评估为:
<meta property="og:image" content='https://s3....amazonaws.com/path/to/image.jpg'/>
注意:
如果图像存储在您自己的应用程序服务器上,则可以将其用作:
<meta property="og:image" content='<%= image_url @recipe.image.url(:fixed) %>'/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句