有没有办法将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
?谢谢。
答案 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 %>