yarn add clipboard.js
app/javascripts/packs/application.js
var ClipboardJS = require('clipboard')
$(document).on("turbolinks:load", function() {
console.log("DEBUG:: turbolinks.load!")
var clipboard = new ClipboardJS('.btn');
console.log(clipboard);
});
gem 'clipboard-rails'
/app/assets/javascripts/application.js
//= require clipboard
$(document).ready(function(){
var clipboard = new Clipboard('.clipboard-btn');
console.log(clipboard);
});
Usage
<!-- Target -->
<textarea id="bar">Mussum ipsum cacilds...</textarea>
<!-- Trigger -->
<button class="btn clipboard-btn" data-clipboard-action="copy" data-clipboard-target="#bar">
Cut to clipboard
</button>
<button class="btn clipboard-btn" data-clipboard-text="foo bar hello">
Cut to clipboard
</button>