My music review app has an image (the album art) for each review (which are called Pins). It used to be that when sharing a review to Facebook, the album art would show as the thumbnail. Now no image shows at all.
When I use the facebook debugger, I get this info:
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.
I understand that I need to set a meta tag similar to this:
<meta property="og:image" content='http://s3.amazonaws.com/theTens/pins/images/000/000/150/medium/arcade-fire-reflektor-cover-500x500_(1).jpg?1387660087'/>
How do I set the meta tag to dynamically get the image url based on the page that the user is sharing?
The image is uploaded with Paperclip, then hosted on Amazon S3.
Edit: Prakash had the right answer below, so here are the helper methods that I wrote in the application helper. (I had to also set the 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
And my meta tags in my head:
<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">
Try adding the following in the layout file:
<meta property="og:image" content="<%= og_image_path %>">
The method og_image_path
- could be defined in the application_helper
- should give the path for the image of the review if present or a default image if not present.
Use the image_file_name
attribute that paperclip provides to set the value of the image. See https://github.com/thoughtbot/paperclip#usage for more details.