有没有办法在ActiveAdmin中将索引传递给嵌套表单?

时间:2017-08-21 12:54:08

标签: ruby-on-rails activeadmin

有没有办法将index传递给activeadmin的嵌套表单部分?我的代码:

<% 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 %>

通常,如果我有迭代,我会像这样传递index<% Post.each_with_index do |post, index| %>,但我怎么能告诉activeadmin,我希望在index声明中有has_many?谢谢。

1 个答案:

答案 0 :(得分:2)

你可以用老式的柜台做到......

<% 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 %>