So I wanted to copy the url of each resource to the clipboard so I tried:
<% @posts.each do |post|%>
<script>
$(document).ready(function(){
var clipboard = new Clipboard('.clipboard-btn');
console.log(clipboard);
});
</script>
<textarea id="bar"><%= post_path(post)%></textarea>
<button class="clipboard-btn" data-clipboard-action="copy" data-clipboard-target="#bar">
Copy to clipboard
</button>
<% end %>
But the problem with that was it only copied the url of the first resource. So I tried this:
<% @posts.each do |post|%>
<script>
$(document).ready(function(){
var clipboard = new Clipboard('.clipboard-btn<%=post.id%>');
console.log(clipboard);
});
</script>
<textarea id="bar<%=post.id%>"><%= post_path(post)%></textarea>
<button class="clipboard-btn<%=post.id%>" data-clipboard-action="copy" data-clipboard-target="#bar<%=post.id%>">
Copy to clipboard
</button>
<% end %>
without any luck