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.
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