1

Is there any way to pass index to activeadmin's nested form partial? The code I have:

<% variant.has_many :variant_currencies, allow_destroy: true, heading: false, new_record: 'Add new price modifier' do |variant_currency| %>
  <% variant_currency.template.render partial: 'variant-currency-form', locals: { variant_currency: variant_currency, index: '??? how to pass it here ???' } %>
<% end %>

Normally, if I have an iteration, I pass index like this: <% Post.each_with_index do |post, index| %>, but how can I tell activeadmin, that I want to have index in that has_many statement? Thanks ahead.

Alex Zakruzhetskyi
  • 1,383
  • 2
  • 22
  • 43

1 Answers1

2

You could do it with an old fashioned counter...

<% counter = 0 %>
<% variant.has_many :variant_currencies, allow_destroy: true, heading: false, new_record: 'Add new price modifier' do |variant_currency| %>
  <% variant_currency.template.render partial: 'variant-currency-form', locals: { variant_currency: variant_currency, index: counter.to_s } %>
  <% counter += 1 %>
<% end %>
SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53