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) %>

5
9

                                    # config/initializers/default_meta.rb

# Initialize default meta tags.
DEFAULT_META = YAML.load_file(Rails.root.join(&quot;config/meta.yml&quot;))

5 (1 Votes)
0
4.6
5
Eeeeeean 110 points

                                    # app/helpers/meta_tags_helper.rb

module MetaTagsHelper
  def meta_title
    content_for?(:meta_title) ? content_for(:meta_title) : DEFAULT_META[&quot;meta_title&quot;]
  end

  def meta_description
    content_for?(:meta_description) ? content_for(:meta_description) : DEFAULT_META[&quot;meta_description&quot;]
  end

  def meta_image
    meta_image = (content_for?(:meta_image) ? content_for(:meta_image) : DEFAULT_META[&quot;meta_image&quot;])
    # little twist to make it work equally with an asset or a url
    meta_image.starts_with?(&quot;http&quot;) ? meta_image : image_url(meta_image)
  end
end

4.6 (5 Votes)
0
5
1
Rick8589 70 points

                                    # config/meta.yml

meta_product_name: &quot;Product Name&quot;
meta_title: &quot;Product name - Product tagline&quot;
meta_description: &quot;Relevant description&quot;
meta_image: &quot;cover.png&quot; # should exist in `app/assets/images/`
twitter_account: &quot;@product_twitter_account&quot;   # required for Twitter Cards

5 (1 Votes)
0
4.5
6
N M 110 points

                                    &lt;title&gt;&lt;%= meta_title %&gt;&lt;/title&gt;
&lt;meta name=&quot;description&quot; content=&quot;&lt;%= meta_description %&gt;&quot;&gt;

&lt;!-- Facebook Open Graph data --&gt;
&lt;meta property=&quot;og:title&quot; content=&quot;&lt;%= meta_title %&gt;&quot; /&gt;
&lt;meta property=&quot;og:type&quot; content=&quot;website&quot; /&gt;
&lt;meta property=&quot;og:url&quot; content=&quot;&lt;%= request.original_url %&gt;&quot; /&gt;
&lt;meta property=&quot;og:image&quot; content=&quot;&lt;%= meta_image %&gt;&quot; /&gt;
&lt;meta property=&quot;og:description&quot; content=&quot;&lt;%= meta_description %&gt;&quot; /&gt;
&lt;meta property=&quot;og:site_name&quot; content=&quot;&lt;%= meta_title %&gt;&quot; /&gt;

&lt;!-- Twitter Card data --&gt;
&lt;meta name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot;&gt;
&lt;meta name=&quot;twitter:site&quot; content=&quot;&lt;%= DEFAULT_META[&quot;twitter_account&quot;] %&gt;&quot;&gt;
&lt;meta name=&quot;twitter:title&quot; content=&quot;&lt;%= meta_title %&gt;&quot;&gt;
&lt;meta name=&quot;twitter:description&quot; content=&quot;&lt;%= meta_description %&gt;&quot;&gt;
&lt;meta name=&quot;twitter:creator&quot; content=&quot;&lt;%= DEFAULT_META[&quot;twitter_account&quot;] %&gt;&quot;&gt;
&lt;meta name=&quot;twitter:image:src&quot; content=&quot;&lt;%= meta_image %&gt;&quot;&gt;

4.5 (6 Votes)
0
4.33
6

                                    # app/controllers/application_controller.rb

def default_url_options
  { host: ENV[&quot;DOMAIN&quot;] || &quot;localhost:3000&quot; }
end

4.33 (6 Votes)
0
4.5
2
Leon Avery 100 points

                                    heroku config:set DOMAIN=www.my_product.com

4.5 (2 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source