Social Media Sharing Buttons Gem for Ruby on Rails
I am trying to find a good gem that will allow me to add social media sharing buttons to my Rails 3 app (similar to the Wordpress plugins AddThis). The key sites that I want to enable sharing with are Facebook, Twitter开发者_高级运维, LinkedIn, and Google+. I want to allow two levels of sharing i.e. the ability to share a link to the site as a whole and the ability to share specific pages or posts on the site. Thanks in advance!
What gems would you recommend?
Install
In your Gemfile
:
gem 'social-share-button'
And install it:
$ bundle install
$ rails generate social_share_button:install
Configure
here https://github.com/huacnlee/social-share-button
As you shop for these widgets you should not think in terms of Rails solutions but Javascript solutions. Since Rails had adopted JQuery as it default JS framework you can also look in that direction.
Here are a few: http://plugins.jquery.com/?s=social
I recommend shareBox
I found shareable to be pretty good.
Haucnlee's gem unfortunately doesn't support counters (currently), but I was able to use https://github.com/iffyuva/social-buttons to implement this for myself. See for a rails 3 gem for sharing content on social media sites in one click walkthrough.
Sharing to Facebook
http://www.facebook.com/dialog/feed?app_id=123456789&link=http://Domain_name/<%= @post.id %>/<%= @post.name %>&picture=<%= @default_image_of_the_post.image_url %>&name=<%= @post.title %>&caption=<%= @post.caption %>&description=<%= @post.description %>&redirect_uri=http://Domain_name/<%= request.original_url %>&display=popup” target=’_blank’>
Note:
app_id = ‘App_Id’ which is given by facebook. U need to register your app in Facebook
check here ‘https://developers.facebook.com‘ go to Apps tab and click on ‘Create a New
App’
link = This is the link for this particular post, if any user clicks on this post in FB, he will be
redirected to this link
picture = Picture for the post
name = Title of the post
caption = Caption for the post
description = Description for the post
redirect_uri = after posting, To which link u want user to be redirected. Its better to give ‘request.original_url’, user will redirect to same page from where he has been sharing the link
Sharing to Linked in
http://www.linkedin.com/shareArticle?mini=true&url=http://Domain_name/<%= @post.id %>/<%= @post.name %>&title=<%= @post.title %>&summary=<%= @post. description %>” target=”_blank”>
Note:
url = This is the link for this particular post, if any user clicks on this post in Linked in, he will be
redirected to this link
Title = Title for the post
summary = Description for the post
http://sapegin.github.io/social-likes/ looks very nice, have a try. It has a plenty of options, wide documentation with examples and customizer.
Know that this is an old question, but in case you're looking for something not using (external) JavaScript which also helps you with the right opengraph/card-metatags, maybe you want to try: https://rubygems.org/gems/social_linker (shameless plug by the author)
精彩评论