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.
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;
.