Q:

rails partial rendering with uniq id

I'm trying to render a partial on a view when user is pressing a button, so actually it's a list of partials (the same partial is rendered more times) I use cocoon gem to render the partials like this:
<%= f.fields_for :features do |s| %>
  <%= render 'feature_fields', f: s %>
<% end %>
<div class="f-input for-button to-right">
  <%= link_to_add_association 'add more', f, :features, :class => "radius blue button" %>
</div>

and in my partial I have this code:
<% div_id = DateTime.now.to_i %>

so the idea is to have an uniq id for every rendered partial but my problem is the partials renders ok but the id is the same, the first id generated is applied to every partial

A:

Since you are using cocoon, using partial counter or any other modification in the partial itself would not help you.
This is because cocoon renders one template for new instances and uses this locally in the browser to generate new nested attribute blocks.
You can use cocoons callbacks to modify the generated block with JS.
See the cocoon readme.

