1

Using Zclip-rails Gem which is a wrapper on top of zClip library. Code Below.

View

<table>
<% File.all.each do |file|
  <tr>
     <td> <%= text_field_tag :name, file.name , id: "text_#{file.id}" %> </td>
     <td> <%= link_to 'Copy to clipboard', 'javascript:void(0)', class: 'copy-to-clipboard', id: "text_#{file.id}" %></td>
    </tr>
</tr>
<%end>
<table>

Javascript

$('a.copy-to-clipboard').zclip({
  copy: "this is the text to copy ankit",
  beforeCopy:function(){
   alert($(this).attr('id'));
 }

});

The Issue is i am getting always a the same id on click of all links made for copy to clipboard For eg: 'text_1'. What i am expecting is that with different rows i should get different id's on click of copy to clipboard.

Any thoughts will be helpful.

AnkitG
  • 6,438
  • 7
  • 44
  • 72
  • Please, paste result code to jsfiddle and show it. – mr.The Jun 27 '13 at 11:24
  • Actually, i do it for you: http://jsfiddle.net/tVZNm/1/ and everything looks fine. So, show your compiled html code. – mr.The Jun 27 '13 at 11:40
  • @mr.The. thanks for creating the fiddle.. i have updated it http://jsfiddle.net/tVZNm/5/ . I need to copy the cells which are there as 11.jpgboo & 12.jpgboo – AnkitG Jun 27 '13 at 12:04

1 Answers1

1

Done: http://jsfiddle.net/tVZNm/10/

Here is problem with table css position: zclip flash wrapper appears on wrong position(at top, left corner of table). So i add wrapper div for links, with posotion: relative;.

Look at this and this threads for details.

Community
  • 1
  • 1
mr.The
  • 445
  • 5
  • 17