Social Share Button Gem for Rails Apps

Objective

Install social share button for your Rails app in just 5 minutes.

Steps

Step 1

Add the gem to the Gemfile.

gem 'social-share-button'

Step 2

Install the gem and generate the config files.

$ bundle install
$ rails generate social_share_button:install

Step 3

Add the require statement for javascript file in application.js:

//= require social-share-button

Step 4

Add the import statement for the CSS in application.scss file:

@import "social-share-button";

Step 5

Add the share button helper to article show page:

<%= social_share_button_tag(@article.title) %>

You will now see the social media share buttons as seen on this page.

Summary

In this article, you learned how to use the social-share-button gem to add social share buttons to your Rails app.

Reference

Social Share Button Gem Home Page


Related Articles


Create your own user feedback survey