Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Sharing Feature With Social Media in Rails App

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 696
    Comment on it

    Sharing Feature With Social Media in Rails App

    As we know these days almost all web applications provide us with the option to share anything on any social,

    media website so that our friends or other users on those social medias could watch it and acknowledge it.

    Even we can add this same feature to our web application by installing a gem called Social-Share-Button.

    The steps to integrate it are as follows : 

    • Add this to your gemfile
    gem 'social-share-button'

    After that run

    $ bundle install

    in your console.

    After successfully running bundle we need to install the social share button through console like this

    $ rails generate social_share_button:install
    • Customizing the buttons in config file

    To choose which social media websites we want to keep for sharing we can edit it by going in config/initializers/social_share_button.rb and then removing the websites you do not want to use.

    SocialShareButton.configure do |config|
      config.allow_sites = %w(twitter facebook linkedin)

    In my case, I am only using twitter facebook and linked in.

    • including javascript for it to app/assets/javascripts/application.js file
    //= require social-share-button
    • including css for it to app/assets/stylesheets/application.css file
    *= require social-share-button
    • Adding the view of social share button to the html file
    <%= social_share_button_tag(@article.title) %>

    I am sharing my articles so in my case I have taken the instance variable of my article model. You can give your own variable at the place of @article.

    So with finally with the help of this gem you can easily share anything on social media.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: