og meta tags not working rails code example
Example 1: og meta tags not working rails
<!-- app/views/offers/show.html.erb -->
<% content_for :meta_title, "#{@offer.name} is on #{DEFAULT_META["meta_product_name"]}" %>
<% content_for :meta_description, @offer.description %>
<% content_for :meta_image, cl_image_path(@offer.photo.path) %>
Example 2: og meta tags not working rails
heroku config:set DOMAIN=www.my_product.com
Example 3: og meta tags not working rails
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"])
meta_image.starts_with?("http") ? meta_image : image_url(meta_image)
end
end
Example 4: og meta tags not working rails
meta_product_name: "Product Name"
meta_title: "Product name - Product tagline"
meta_description: "Relevant description"
meta_image: "cover.png"
twitter_account: "@product_twitter_account"
Example 5: og meta tags not working rails
<title><%= meta_title %></title>
<meta name="description" content="<%= meta_description %>">
<!-- Facebook Open Graph data -->
<meta property="og:title" content="<%= meta_title %>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<%= request.original_url %>" />
<meta property="og:image" content="<%= meta_image %>" />
<meta property="og:description" content="<%= meta_description %>" />
<meta property="og:site_name" content="<%= meta_title %>" />
<!-- Twitter Card data -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="<%= DEFAULT_META["twitter_account"] %>">
<meta name="twitter:title" content="<%= meta_title %>">
<meta name="twitter:description" content="<%= meta_description %>">
<meta name="twitter:creator" content="<%= DEFAULT_META["twitter_account"] %>">
<meta name="twitter:image:src" content="<%= meta_image %>">
Example 6: og meta tags not working rails
def default_url_options
{ host: ENV["DOMAIN"] || "localhost:3000" }
end
Example 7: og meta tags not working rails
DEFAULT_META = YAML.load_file(Rails.root.join("config/meta.yml"))