Skip to content

Instantly share code, notes, and snippets.

@bqst
Created March 16, 2018 09:48
Show Gist options
  • Save bqst/b201e4ea244683ebe0954b3bc154c714 to your computer and use it in GitHub Desktop.
Save bqst/b201e4ea244683ebe0954b3bc154c714 to your computer and use it in GitHub Desktop.
# app/helpers/meta_tags_helper.rb
module MetaTagsHelper
def meta_title
content_for?(:meta_title) ? content_for(:meta_title) : DEFAULT_META["meta_title"]
end
def meta_description
content_for?(:meta_description) ? content_for(:meta_description) : DEFAULT_META["meta_description"]
end
def meta_image
meta_image = (content_for?(:meta_image) ? content_for(:meta_image) : DEFAULT_META["meta_image"])
# ajoutez la ligne ci-dessous pour que le helper fonctionne indifféremment
# avec une image dans vos assets ou une url absolue
meta_image.starts_with?("http") ? meta_image : image_url(meta_image)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment