How to retrieve images for each posted article with Rails 6meta tag & OGP settings

Asked 1 years ago, Updated 1 years ago, 278 views

I am trying to get images of each posted article page on the site using meta tag & OGP settings in Rails 6, but it is not working.

The following code is written at the top of the html.erb page to retrieve.
You can get the title and description, but only the image is not reflected.
I am referring to the application_helper.rb image.

<%set_meta_tags title: @article.title, description: @article.content1, image: @article.picture1.url%>

Also, as I mentioned below, the application_helper.rb is
I will refer to it.

<%set_meta_tags title:@article.title, description:@article.content1%>
<meta property="og:image"content="@article.picture1.url">

Please refer to the article below for instructions.

How to configure meta tag & OGP settings in the Rails app
Dynamically generate OGP images for recipe pages

Please tell me how to resolve it.

ruby-on-rails ruby html

2022-12-14 08:14

1 Answers

I understand that using meta-tagsgem, using set_meta_tags and specifying image as the keyword argument does not print what you specify in the HTML meta tag that is actually output.

First, the meta-tagsgem set_meta_tags does not take the image keyword argument.See the gem documentation.Probably confused with image_src or og around image: https://github.com/kpumuk/meta-tags#allowed-options-for-display_meta_tags-and-set_meta_tags-methods

For example, if you specify og:image, you can do the following:

set_meta_tagsog: {image: "Put URL here"}


2022-12-14 08:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.