如何在Rails中使用social_share_button共享图像和描述? [英] How to share image and description using social_share_button in rails?

查看:79
本文介绍了如何在Rails中使用social_share_button共享图像和描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想共享广告系列名称以及图片和说明,但仅共享名称

I want to share campaign name along with image and description but it only share name

<%= social_share_button_tag(@campaign.project.project_name, :image => @campaign.campaign_image_url) %>

有什么方法可以在社交媒体上分享图像?

Is there any way to share image on social media?

推荐答案

从问题的代码段中,我猜您正在使用社交共享按钮宝石.

From the code snippets in the question I'm guessing you're using the social-share-button gem.

不幸的是,如果使用传递给social_share_button_tag的属性取决于您要共享的平台,并且每个接受的参数都不相同.例如,当您尝试以这种方式共享时,Facebook不允许您指定图像.您可以在

Unfortunately, if an attribute you pass in to the social_share_button_tag is used depends on the platform you're trying to share on to, and each of them accept different params than the other. For example, Facebook doesn't allow you to specify images when you try to share that way. You can see the attributes that are passed into each of the platforms in the social-share-button.coffee file.

使图像显示的最佳方法是为打开的图形包括元标记,其中包括该页面的标题,描述,要使用的图像等.您可以在在此处打开图形标记中查看所有相关信息.如果在渲染页面时在页面的header部分中渲染这些标签,则共享页面时将显示这些图像和其他信息.例如:

The best way to get the image to appear is to include meta tags for open graph which includes the title, description, image to use etc for that page. You can see all the relevant Open Graph Markup here. If you render those tags in the header section of your page when its rendered, those images and other information will appear when you share the page. For example:

<meta property="og:title" content="<%= @campaign.project.project_name %>" />
<meta property="og:description" content="<%= @campaign.project.description %>" />
<meta property="og:image" content="<%= @campaign.campaign_image_url %>" />

此外,即使用户直接使用URL共享页面而不是通过该插件共享页面,它也会显示.现在,这已成为非常标准的标准,其他平台(例如Slack等)也将使用这些标签来确定如何在其平台上显示链接.

Additionally, it'll appear even if the user shares the page using the URL straight, rather than going through that plugin. This has become pretty standard now and other platforms such as Slack etc will also use those tags to determine how to display a link on their platform.

这篇关于如何在Rails中使用social_share_button共享图像和描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆