首页 > 解决方案 > 带有导轨的社交共享按钮宝石中的错误

问题描述

我一直在尝试使用社交分享按钮 gem。请参阅下面的链接。https://github.com/huacnlee/social-share-button

但问题是我不明白什么

<%= social_share_button_tag(@post.title) %>

从链接的意思。我正在使用控制器“条目”,所以我做到了

<%= social_share_button_tag(@Entry.title) %>

但它没有用。所以我只是做了

<%= social_share_button_tag("") %>

它确实有效,只是当我单击显示的按钮时,它没有转到“共享链接”。

希望我能从中得到一些理解!谢谢!

标签: ruby-on-railsrubygems

解决方案


使用 gem 的语法如下:

social_share_button_tag("text to share")

或者如果需要 Facebook 分享按钮:

social_share_button_tag("text to share", url: 'https://www.yourdomain.com', desc: 'description for facebook')

在您的情况下,您需要用代码中的实际变量替换“要共享的文本”,可以是@post.title@ntry.title并为url:desc:

所以它看起来像

social_share_button_tag(@entry.title, url: @entry.url, desc: @entry.description)

希望能帮助到你!


推荐阅读