3

I am developing an application in Rails 3 where I have a text field which contains a URL:

 <input type="text" readonly="readonly" value="<%= linkbunch_url(@link.link) %>" class="span4" id="url_copy" />

Next to this I have a button:

<button type="button" id="copy_link" class="btn btn-success"><i class="icon-share" ></i>&nbsp;&nbsp; Copy To ClipBoard</button>

When someone clicks on this button, I want the url in the text field to be copied into the clipboard. How do I do this?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Siddharth
  • 833
  • 6
  • 12
  • 25

2 Answers2

3

There is no way to do that with Ruby through the web browser.

You need a JavaScript method instead. Look at "How to copy to the clipboard in JavaScript?".

Community
  • 1
  • 1
VadimAlekseev
  • 2,228
  • 1
  • 18
  • 16
  • I'm following the method mentioned https://github.com/HaNdTriX/zclip-rails and also from http://www.steamdev.com/zclip/ – Siddharth Jan 10 '13 at 06:46
3

This is the solution that worked for me. I used this gemfile

and only installed these gems:

gem 'clipboard-rails'
gem 'jquery-rails'

also, include these in your app/assets/javascripts/application.js file

//= require clipboard
//= require jquery
//= require jquery_ujs
jasmineq
  • 521
  • 5
  • 7