简体   繁体   English

如何在 Rails 应用中实现社交分享?

[英]How to implement the social sharing in rails app?

I want to implement the social sharing feature of the articles which have been posted in my rails app.我想实现已发布在我的 rails 应用程序中的文章的社交共享功能。 I tried following the documentation of gem 'social-share-button' where the following steps were followed :我尝试遵循gem 'social-share-button'的文档,其中遵循以下步骤:

step 1: Add //= require rails-social-share-button in app/assets/javascripts/application.js第 1 步:在 app/assets/javascripts/application.js 中添加 //= require rails-social-share-button

step 2: Add *= require rails-social-share-button in app/assets/stylesheets/application.css第 2 步:在 app/assets/stylesheets/application.css 中添加 *= require rails-social-share-button

step 3: use the social_share_button_tag helper method in views to display the social share buttons.第三步:在view中使用social_share_button_tag helper方法来显示社交分享按钮。 for eg = rails_social_share_button_tag('Share to Facebook', url: article_path(@article), desc: @article.content)例如= rails_social_share_button_tag('Share to Facebook', url: article_path(@article), desc: @article.content)

Error : undefined method `rails_social_share_button_tag' for #<#:0x00005574ff28ec30>错误:#<#:0x00005574ff28ec30> 的未定义方法`rails_social_share_button_tag'

You're missing a step or two from the gem's readme.您错过了 gem 的自述文件中的一两步。 The order of the instructions in the readme is a little misleading.自述文件中的说明顺序有点误导。 Did you run rails generate rails_social_share_button:install ?您是否运行rails generate rails_social_share_button:install You may also want to check the contents of the "config/initializers/rails_social_share_button.rb" file after you've run that generator.您可能还想在运行该生成器后检查“config/initializers/rails_social_share_button.rb”文件的内容。

Alternatively, you may want to use the "social-share-button" gem.或者,您可能想要使用“社交分享按钮”宝石。 It looks like the one you're using, with its longer name, is a copy of everything in shorter-named "social-share-button" gem.看起来您正在使用的名称较长的那个是名称较短的“社交分享按钮” gem 中所有内容的副本。 Also it looks like the "social-share-button" gem has been around longer and is better maintained, as it already includes one bugfix that the gem you're using does not.此外,看起来“社交分享按钮”gem 存在的时间更长并且维护得更好,因为它已经包含一个您正在使用的 gem 没有的错误修复。 I'd recommend first switching gems and then running bundle install .我建议先切换 gems,然后运行bundle install After switching gems, you should run the generator command listed in the readme for social-share-button , check the config file as the readme recommends, and then update your views accordingly.切换 gem 后,您应该运行social-share-button的自述文件中列出的生成器命令, 按照自述文件的建议检查配置文件,然后相应地更新您的视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM