Rails 如何在 fields_for 中获取序号

santochancf · 2012年07月30日 · 最后由 mouse_lin 回复于 2012年07月30日 · 2837 次阅读

通过 form 结合 fields_for 可以实现迭代。 请问如何获取迭代中显示序号……

<%= f.fields_for :line_items do |line| %>

#how to get the index <%end %>

<% @line_items.each_with_index do |v, i|%>
  <%= f.fields_for :line_items do |line| %>
    <%= i %> # the index you want 
  <%end %>
<% end %>
需要 登录 后方可回复, 如果你还没有账号请 注册新账号