[Ruby] [Rails] How to create Twitter share button

less than 1 minute read

Target

ezgif.com-video-to-gif.gif

Development environment

・Ruby: 2.5.7 Rails: 5.2.4 ・Vagrant: 2.2.7 ・VirtualBox: 6.1 ・OS: macOS Catalina

Premise

Implemented below.

Slim introductionBootstrap3 installedFont Awesome introduction

Implementation

slim:books/show.html.slim


= link_to "Disseminate https://twitter.com/share?url=#{ request.url }&text=#{ @book.title }to everyone on Twitter!", class:'btn btn-default', target:'_blank' do
   i.fab.fa-twitter style='color: #3399FF;'
   | Share on Twitter

url=#{ request.url } ➡︎ Embed the URL of the page in the tweet.

&text=# ➡︎ Create tweet content.