Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

og:image meta tag in ruby on rails

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.

like image 210
MikeHolford Avatar asked Mar 31 '14 20:03

MikeHolford


1 Answers

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) %>'/>
like image 53
Kirti Thorat Avatar answered Oct 03 '22 08:10

Kirti Thorat