如何使用嵌套字段生成序列号

时间:2015-07-29 05:19:47

标签: ruby-on-rails

点击添加播放器后如何生成播放器位置? 我正在使用Ruby 1.9.3 rails 3.2.9和嵌套表单。 我的代码是:

    <%= f.fields_for :event_players, :validate=>true do |player| %>
  position : <%= player.text_field :position,:placeholder=>"Pos" %>
  player name <%= player.text_field :name ,  :class => 'search_player_live_result-new',:placeholder=>"Player",:validate=>true%>
<%end%>
 <%= f.link_to_add "add player", :event_players, :class=>"icon-plus no_of_places",:style=>"font-size: 14px;", :data => { :target => "#pokerResultPlayers" } %> 

1 个答案:

答案 0 :(得分:0)

您可以使用:

<%= f.fields_for :event_players, :validate=>true do |player| %>
  serial number: <%= player.options[:child_index] %>
  position : <%= player.text_field :position, :placeholder => "Pos" %>
  player name <%= player.text_field :name, :class => 'search_player_live_result-new', :placeholder => "Player", :validate => true %>
<% end %>