Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
How can I use clipboard.js with importmap in rails 7

I want to add a Copy to Clipboard button to my page in a Ruby on Rails 7 project.

config/importmap.rb:

pin "clipboard.js", to: "https://cdn.jsdelivr.net/npm/clipboard@2.0.10/dist/clipboard.min.js", preload: true

app/javascript/application.js:

import { ClipboardJS } from "clipboard.js"

...

document.addEventListener('turbo:load', (event) => {
  new ClipboardJS('.js-clipboard', {
    text: function(trigger) {
      return trigger.getAttribute('data-clipboard-text')
    }
  })
})

But after page loads I get an error:

Uncaught SyntaxError: import not found: ClipboardJS
  • Rails 7.0.2.3
  • Ruby 3.0.2
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hi try to install clipboard by using the command

bin/importmap pin clipboard

Then instead of importing the module ClipboardJS by using import { ClipboardJS } from "clipboard.js", import just the class this way:

import ClipboardJS from 'clipboard'

Everything else is correct.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!