I have some dynamic images defined as follows on my page:
<%= image_tag(@recipe.image.url(:fixed), :class => 'recipe_image_show') %>
I am looking for a way to define og:image with this code. The og:description code seen below works perfectly:
<meta property="og:description" content= "<%= @recipe.description %>" />
But if I use the code below then it doesn't want to work:
<meta property="og:image" content='<%= image_tag(@recipe.image.url(:fixed), :class => 'recipe_image_show') %>'/>
Any suggestions? I realised I have used single quotes here but using double quotes for some reason results the page to disregard the '/>' part of the meta tag and display it as text.
As per the chat discussion, OP is hosting the images on S3.
So, define the meta
tag as below:
<meta property="og:image" content='<%= @recipe.image.url(:fixed) %>'/>
This will be evaluated to:
<meta property="og:image" content='https://s3....amazonaws.com/path/to/image.jpg'/>
NOTE:
If image was stored on the your own application server then you could use it as:
<meta property="og:image" content='<%= image_url @recipe.image.url(:fixed) %>'/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With