Rails:如何设置og:image元标签?
Rails: How to set og:image meta tags?
我的音乐评论应用程序为每条评论(称为 Pin 图)提供一张图片(专辑封面)。过去,在将评论分享到 Facebook 时,专辑封面会显示为缩略图。现在根本没有图像显示。
当我使用 facebook debugger 时,我得到以下信息:
og:image was not defined, could not be downloaded or was not big
enough. Please define a chosen image using the og:image metatag, and
use an image that's at least 200x200px and is accessible from
Facebook. Image
'http://s3.amazonaws.com/theTens/pins/images/000/000/150/medium/arcade-fire-reflektor-cover-500x500_(1).jpg?1387660087'
will be used instead.
我知道我需要设置一个类似这样的元标记:
<meta property="og:image" content='http://s3.amazonaws.com/theTens/pins/images/000/000/150/medium/arcade-fire-reflektor-cover-500x500_(1).jpg?1387660087'/>
如何设置元标记以根据用户共享的页面动态获取图像url?
图像使用 Paperclip 上传,然后托管在 Amazon S3 上。
编辑:Prakash 在下面给出了正确答案,所以这里是我在应用程序帮助器中编写的帮助器方法。 (我还必须设置 url_path)
def og_image_path
if @pin.present?
@pin.image.url
end
end
def og_url_path
if @pin.present?
"http://www.thetens.us/pins/" + @pin.to_param
end
end
我脑子里的元标签:
<meta property="og:image" content="<%= og_image_path %>">
<meta property="og:url" content="<%= og_url_path %>">
<meta property="og:title" content="Album Review">
<meta property="og:description" content="The Music Review Site Where YOUR Opinion Matters">
尝试在布局文件中添加以下内容:
<meta property="og:image" content="<%= og_image_path %>">
方法 og_image_path
- 可以在 application_helper
中定义 - 应该给出评论图像的路径(如果存在)或默认图像(如果不存在)。
使用回形针提供的image_file_name
属性设置图像的值。有关详细信息,请参阅 https://github.com/thoughtbot/paperclip#usage。
我的音乐评论应用程序为每条评论(称为 Pin 图)提供一张图片(专辑封面)。过去,在将评论分享到 Facebook 时,专辑封面会显示为缩略图。现在根本没有图像显示。
当我使用 facebook debugger 时,我得到以下信息:
og:image was not defined, could not be downloaded or was not big enough. Please define a chosen image using the og:image metatag, and use an image that's at least 200x200px and is accessible from Facebook. Image 'http://s3.amazonaws.com/theTens/pins/images/000/000/150/medium/arcade-fire-reflektor-cover-500x500_(1).jpg?1387660087' will be used instead.
我知道我需要设置一个类似这样的元标记:
<meta property="og:image" content='http://s3.amazonaws.com/theTens/pins/images/000/000/150/medium/arcade-fire-reflektor-cover-500x500_(1).jpg?1387660087'/>
如何设置元标记以根据用户共享的页面动态获取图像url?
图像使用 Paperclip 上传,然后托管在 Amazon S3 上。
编辑:Prakash 在下面给出了正确答案,所以这里是我在应用程序帮助器中编写的帮助器方法。 (我还必须设置 url_path)
def og_image_path
if @pin.present?
@pin.image.url
end
end
def og_url_path
if @pin.present?
"http://www.thetens.us/pins/" + @pin.to_param
end
end
我脑子里的元标签:
<meta property="og:image" content="<%= og_image_path %>">
<meta property="og:url" content="<%= og_url_path %>">
<meta property="og:title" content="Album Review">
<meta property="og:description" content="The Music Review Site Where YOUR Opinion Matters">
尝试在布局文件中添加以下内容:
<meta property="og:image" content="<%= og_image_path %>">
方法 og_image_path
- 可以在 application_helper
中定义 - 应该给出评论图像的路径(如果存在)或默认图像(如果不存在)。
使用回形针提供的image_file_name
属性设置图像的值。有关详细信息,请参阅 https://github.com/thoughtbot/paperclip#usage。