Social Media sharing Buttons in Ruby on Rails

trickydiddy picture trickydiddy · Mar 28, 2017 · Viewed 7.2k times · Source

I'm trying to add custom social media sharing buttons in a blog app in Ruby on Rails. It is important for me that a pop-up window will show for sharing the "post" meaning I want to include Javascript.

Unfortunately this code does not work:

  <!-- Twitter -->
  <a oneclick="javascript:window.open('http://twitter.com/share?text=<%= @post.title %> 
  by Martin Bortowski - &amp;url=<%= url_for([@post, {only_path: false}]) %>',
  '_blank', 'width=800, height=500, top=200, left=300');void(0);"><i class="fa fa-twitter"></i></a>

  <!-- Facebook -->
  <a oneclick="javascript:window.open('http://facebook.com/sharer.php?u=<%= url_for([@post, {only_path: false}]) %>',
  '_blank', 'width=800, height=500, top=200, left=300');void(0);"><i class="fa fa-facebook"></i></a>

  <!-- Google Plus -->
  <a oneclick="javascript:window.open('https://plus.google.com/share?url=<%= url_for([@post, {only_path: false}]) %>',
  '_blank', 'width=800, height=500, top=200, left=300');void(0);"><i class="fa fa-google-plus"></i></a>

When I click on a button nothing happens. What I am missing? Can someone help me please? If you need further information just let me know.

Answer

Dnyanarth lonkar picture Dnyanarth lonkar · Mar 28, 2017

There are number of gems available in ruby on rails for implementing social shairing feature below are few links

  1. https://github.com/huacnlee/social-share-button
  2. https://github.com/hermango/shareable