Social Media sharing Buttons in Ruby on Rails

落爺英雄遲暮 提交于 2019-12-23 02:53:05

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/43066371/social-media-sharing-buttons-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!