lundi 11 avril 2016

No Structured data present Google Open Graph Meta tags Ruby On Rails

I'm using browser gem for robots/crawlers detection . In my initializers/browser.rb I have the following

Rails.configuration.middleware.use Browser::Middleware do
    if browser.bot?
        url_params = request.env["PATH_INFO"].split("/")
        request.env["PATH_INFO"] = "api/v1/shared/show_preview/#{url_params.last}"
    end
end

And in my shared/show_preview I have the following

def show_preview
    @question = to_array(@question)
    question_package = formatting_questoins(@question,params[:id].to_i)
    @searched_question = question_package.first
    puts @searched_question

    respond_to do |format|
        format.html { render "show_preview" }
        format.json  { render "show_preview.html.erb" }
    end
end

And In my show_preview.html.erb I have the following

<meta property="og:url"                content="http://ift.tt/1Vib2Pq @searched_question['permalink'] %>" />
<meta property="og:type"               content="article" />
<meta property="og:title"              content="Courting The Law" />
<meta property="og:description"        content="<%= @searched_question['description'] %>" />
<meta property="og:image"              content="http://ift.tt/23xFo1T" />
<meta property="og:image:type"         content="image/png" />
<meta property="og:image:width"        content="200" />
<meta property="og:image:height"       content="200" />

<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="http://ift.tt/1Vib2Pq @searched_question['permalink'] %>" />
<meta name="twitter:title" content="Courting The Law" />
<meta name="twitter:description" content="<%= @searched_question['description'] %>" />
<meta name="twitter:image" content="http://ift.tt/1Vib2Ps" />

On facebook when i share the Url for the specific post , It work perfect , I mean image / description and title appears on the right place . But In case of Google # twitter nothing appears right . I mean no image / description or title is displayed for google (just a simple url of post appears) while in case of twitter it's just Link and image . When i tried the link on Goole Debugger and Twitter card validator It says "No Structured data present"

Aucun commentaire:

Enregistrer un commentaire