Daily Glow Daily Glow - 2 years ago 88
Ruby Question

How to share a post in twitter using ruby on rails?

I am trying to share a post created in rails which is just a text content. Coding to share that post's title and url using this code

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

But i don't know what the problem is but when i click it nothing happen .
any one tell me whats the problem or suggest me some other way of code to share my post's title and comment.

Answer Source

You can use the pretty-social jquery plugin. Add this in a javascript file:


To include the plugin, you can paste the plugin file in your assets or vendor folder.

And this on your posts:

<div class="prettySocial" data-type="twitter" data-url="<%= request.original_url %>" data-description = "<%= @post.content %>" data-media = "<%= @post.main_photo %>"><%= image_tag("twitter.png")%>

You'll get a twitter icon, which will trigger a share onClick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download