我的页面上有一些动态图片定义如下:
<%= 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') %>'/>
有什么建议吗?我意识到我在这里使用了单引号,但出于某种原因使用双引号导致页面忽略元标记的“/>”部分并将其显示为文本。
最佳答案
根据聊天讨论,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) %>'/>
关于ruby-on-rails - og :image meta tag in ruby on rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22771832/