轨道3宝石在点击社交媒体网站上分享内容 [英] rails 3 gem for sharing content on social media sites in one click

查看:166
本文介绍了轨道3宝石在点击社交媒体网站上分享内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从不同的社交媒体网站我的Web应用程序共享内容(FB,Twitter的,谷歌+,的SoundCloud)的点击? Instagram的也有类似的功能。

Is it possible to share content from my web application on different social media sites (fb, twitter, google+, soundcloud) in one click? Instagram has similar feature.

有栏杆宝石可用的是什么?
指针教程将AP preciated。

Is there rails gem available for that? Pointers to tutorials will be appreciated.

推荐答案

虽然这是事实的code来实现社交分享按钮是相当简单的,通常可以从该网站的例子,直接复制到你的模板,但使用宝石来管理code好处:

Why use a gem

While it's true the code to implement social sharing buttons is quite straightforward and can usually be copied directly from that site's examples into your template, there are benefits to using a gem to manage that code:


  • 它有助于维持在codeBase的(干)分离关注。如果你打算在多个视图使用这些按钮,你可能想反正写一些辅助模板函数。

  • It helps maintain separation of concerns in your codebase (DRY). If you are going to be using these buttons in multiple views, you'd probably want to write some helper template functions anyway.

您不必使您的应用程序是最新的,在每个共享按钮的实施任何更改(只要你选择的是维护良好的宝石)

You don't have to keep your app up to date with any changes in the implementation of each sharing button (provided the gem you choose is well-maintained)

我知道这是一个古老的线程,但我偶然发现了它寻找社会化分享创业板导轨,因为我得到了一个工作解决方案,我想和大家分享。

I know this is an old thread, but I stumbled upon it looking for "the" social sharing gem for rails, and since I got to a working solution I wanted to share.

我能找到两个稍微积极维护宝石:

I was able to find two somewhat actively maintained gems:


  • https://github.com/huacnlee/social-share-button - 这支持了大量的网站,但使用的是简单的实现。它不支持像柜台等格式的更高级的功能,因为它不是要求完整的iframe实现。但似乎有亚洲主要的社交网络的良好覆盖。

  • https://github.com/iffyuva/social-buttons - 这个只支持Facebook的,G +,Twitter和Pinterest的。然而,这是一个更全功能的抽象,因此它的工作对我的使用情况下(在FB,G +,Twitter的,装柜)。

  • https://github.com/huacnlee/social-share-button - This supports a large number of sites, but uses a simple implementations. It doesn't support more advanced functionality like counters and other formats, because it's not calling the full iframe implementations. But it seems to have excellent coverage of the main asian social networks.
  • https://github.com/iffyuva/social-buttons - This only supports Facebook, G+, Twitter, and Pinterest. However, it is a more fully-featured abstraction and so it worked for my use case (the FB, G+, Twitter, with counters).

要使用后者,通常可以按照GitHub的页面上的说明,也有一些例外:

To use the latter, you can generally follow the instructions on the github page, with a few exceptions:

我必须设置宝石的来源,而不是RubyGems的Github上的,因为rubygem线已经过时,并有一些堵漏洞。所以:

I had to set the source of the gem to github instead of rubygems, because the rubygem line was out of date and had some blocking bugs. So:

宝石'社会的按钮,混帐:混帐://github.com/iffyuva/social-buttons.git',分支:'主人'

Facebook的对话框一直关闭你打开之后,如果他们的抓取工具就无法得到他们的网址 - 如果你从本地主机的工作会出现这种情况,所以请确保您指定的URL。说真的,你的应用程序应该知道你对你的内容cannonical的网址是什么,所以在您的视图:

The facebook dialog box keeps closing right after you open it if their crawler can't get to their url - this will happen if you're working from localhost, so make sure you specify the URL. Really, your application should know what your cannonical url for your content is, so in your view:

URL = request.protocol + HOST_FOR_CRAWLERS + model_path(@model)

最后,文件是如何形成的参数为Facebook功能有点不清楚,或者你需要脚本:真的谷歌加上标签来部署其脚本。

Finally, the documentation was a little unclear on how to form arguments for the facebook function, or that you need script: true for the google plus tag to deploy its script.

下面是我的看法:

< UL类=社会共享列表列表内联>
  <李班=TWT>
            <%= tweet_button计数:'横',
                             相关:realted_twitter_handle',
                             文本:@ model.title +''+网址,
                             网址:网址,
                             通过:your_twitter_handle'%GT;
  < /李>
  <李班=GP>
    <%= google_plus_button HREF:URL,
                           脚本:真实,
                           注释:泡沫,
                           大小:中等%GT;
  < /李>
  <李班=FB>
    &所述;%= like_button your_facebook_app_id,
                    动作:'像',
                    HREF:URL,
                    布局:button_count,
                    发送:真正的%GT;
  < /李>
< / UL>

在我顶嘴,我添加了一些规则,以规范化的iframe嵌入常规尺寸:

In my sass, I added some rules to normalize the iframes to regular inline sizing:

ul.social股列表{
  李{
    &安培; .twt {保证金右:-35px;保证金底:-5px;}
    &安培; .gp {保证金右:-33px;保证金底:-5px;}
    &安培; .fb {位置:绝对;}
  }
}

这篇关于轨道3宝石在点击社交媒体网站上分享内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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