Skip to content

Instantly share code, notes, and snippets.

@richjdsmith
Created January 25, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richjdsmith/5e647814ef216707d01b6a789803d260 to your computer and use it in GitHub Desktop.
Save richjdsmith/5e647814ef216707d01b6a789803d260 to your computer and use it in GitHub Desktop.
Rails Share on Social Media Links No Javascript
<div class="flex">
<%= link_to "https://www.linkedin.com/shareArticle?mini=true&url=#{request.original_url}&title=#{@post.title.gsub(/\s+/, "%20")}&summary=#{@post.description.gsub(/\s+/, "%20")}", target: '_blank', rel: 'noopener', alt: 'Share on LinkedIn', class: 'no-underline mr-1 text-indigo-dark hover:text-indigo-light' do %>
<%= inline_svg('images/linkedin_share_icon.svg', class: 'h-8 w-8 fill-current ', title: 'Share on LinkedIn', width: '100%', height: '100%') %>
<% end %>
<%= link_to "http://twitter.com/share?text=I found this great article: #{@post.title}&url=#{request.original_url}&hashtags=thegoodvine", target: '_blank', rel: 'noopener', alt: 'Share on Twitter', class: 'no-underline mx-1 text-indigo-dark hover:text-indigo-light' do %>
<%= inline_svg('images/twitter_share_icon.svg', class: 'h-8 w-8 fill-current ', title:'Share on Twitter', width: '100%', height: '100%') %>
<% end %>
<%= link_to "https://www.facebook.com/dialog/share?app_id=#{Rails.application.credentials[Rails.env.to_sym][:facebook][:app_id]}&display=popup&href=#{request.original_url}&t=#{@post.title}&src=sdkpreparse", target: '_blank', rel: 'noopener', alt: 'Share on Facebook', class: 'no-underline mx-1 text-indigo-dark hover:text-indigo-light' do %>
<%= inline_svg('images/facebook_share_icon.svg', class: 'h-8 w-8 fill-current ', title:'Share on Facebook', width: '100%', height: '100%') %>
<% end %>
<%= link_to "http://www.reddit.com/submit?url=#{request.original_url}&title=#{@post.title}", target: '_blank', rel: 'noopener', alt: 'Share on Reddit', class: 'no-underline mx-1 text-indigo-dark hover:text-indigo-light' do %>
<%= inline_svg('images/reddit_share_icon.svg', class: 'h-8 w-8 fill-current ', title:'Share on Reddit', width: '100%', height: '100%') %>
<% end %>
</div>
@richjdsmith
Copy link
Author

The above relies on the following gems:

  1. https://github.com/jamesmartin/inline_svg

As well as it assumes you are using Tailwind to Style It.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment