Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get index in partial with fields_for on nested records [duplicate]

Given:

<%= f.fields_for :socials do |builder| %>
  <%= render :partial => "social_fields", :locals => { :f => builder} %>
<% end %>

how can I get a counter/index inside the _social_fields.html.erb counter (in order to to something on the last item)? social_fields_counter seems to only be generated if you explicitly pass :collection to render, but these are nested objects with accepts_nested_attributes_for :socials in the parent.

like image 962
jprosevear Avatar asked Dec 11 '22 17:12

jprosevear


1 Answers

Inside _social_fields.html.erb:

<%= f.options[:child_index] %>
like image 57
Valery Kvon Avatar answered Jan 04 '23 23:01

Valery Kvon