问题
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 - &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
- https://github.com/huacnlee/social-share-button
- https://github.com/hermango/shareable
来源:https://stackoverflow.com/questions/43066371/social-media-sharing-buttons-in-ruby-on-rails