og meta tags not working rails

To make sure og meta tags work in a Ruby on Rails application, you can follow these steps:

  1. Install the meta-tags gem by adding it to your Gemfile and running the bundle install command.

ruby gem 'meta-tags'

  1. In your Rails layout file (usually app/views/layouts/application.html.erb), add the following code within the <head> section to set the default og meta tags:

erb <head> <%= display_meta_tags site: 'Your Website', title: 'Your Page Title', description: 'Your Page Description' %> </head>

This code uses the display_meta_tags helper provided by the meta-tags gem to generate the necessary og meta tags.

  1. In your controller, you can customize the og meta tags for each specific page by setting the appropriate values. For example:

ruby class PagesController < ApplicationController def home set_meta_tags og: { title: 'Home Page', description: 'Welcome to our website!', image: 'http://example.com/image.jpg' } end end

In this example, the set_meta_tags method is used to set the og meta tags for the home action of the PagesController. You can customize the title, description, and image values to match your specific needs.

  1. To verify that the og meta tags are working correctly, you can check the HTML source of your page. Right-click on the page and select "View Page Source" or "Inspect Element" in your browser. Look for the <meta property="og:..."> tags within the <head> section. If the og meta tags are present and have the correct values, then they should work as expected.

By following these steps, you should be able to make og meta tags work in your Ruby on Rails application.