How to share image and description using social_share_button in rails?

南笙酒味 提交于 2019-12-02 15:59:09

问题


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?


回答1:


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

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.

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 %>" />

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.



来源:https://stackoverflow.com/questions/42691886/how-to-share-image-and-description-using-social-share-button-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!