Skip to content

Instantly share code, notes, and snippets.

@stereodenis
Last active August 10, 2021 17:00
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stereodenis/d5749a0f17b1b53b5963 to your computer and use it in GitHub Desktop.
Save stereodenis/d5749a0f17b1b53b5963 to your computer and use it in GitHub Desktop.
social meta tags helper ruby on rails 4
def social_meta_tags
title = "#{(content_for?(:title) ? (strip_tags(content_for(:title)).html_safe + ' / ') : '')}#{t('project_title')}"
description = content_for?(:description) ? content_for(:description) : ''
image = if @doc.present?
image_url(@doc.cover_photo.cover.url)
elsif @main.present?
image_url(@main.cover_photo.cover.url)
else
''
end
content_tag(:title, title) +
content_tag(:meta, nil, content: title, property: 'og:title') +
content_tag(:meta, nil, content: description, property: 'og:description') +
content_tag(:meta, nil, content: "#{request.original_url}?title=#{title}", property: 'og:url') +
content_tag(:meta, nil, content: image, property: 'og:image') +
content_tag(:meta, nil, content: title, name: 'title') +
content_tag(:meta, nil, content: description, name: 'description') +
content_tag(:link, nil, href: image, rel: 'image_src').html_safe +
content_tag(:meta, nil, content: 'twitter summary', name: 'twitter:card') +
content_tag(:meta, nil, content: title, name: 'twitter:title') +
content_tag(:meta, nil, content: description, name: 'twitter:description') +
content_tag(:meta, nil, content: image, name: 'twitter:image') +
content_tag(:meta, nil, content: title, itemprop: 'name') +
content_tag(:meta, nil, content: description, itemprop: 'description') +
content_tag(:meta, nil, content: image, itemprop: 'image')
end
@EddieOne
Copy link

EddieOne commented Jul 8, 2017

content_tag will do this <meta></meta>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment