当用户添加一个级别(一个新表单)时,我试图在下面的表单中按数字递增标题。例如,当用户单击添加级别时,它应该显示“级别 2”,如果他们添加另一个级别,则显示“级别 3”
这是我想增加标题的第二部分
<fieldset class="levelCreator">
<%= f.label :title, "Level"%> <br /><%# This is what I would like to increment %>
<%= f.text_field :title %><br />
<%= f.hidden_field :_destroy %>
<%= link_to "remove", '#', class: "btn btn-danger btn-mini remove_fields" %>
<%= f.fields_for :steps do |builder| %>
<%= render 'step_fields', f: builder %>
<% end %>
<%= link_to_add_fields "add step", f, :steps %>
这是添加级别按钮存在的第一部分
<%= form_for(@course) do |f| %>
<%= render 'shared/error_messages_courses' %>
<div class="courseCreator">
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :description %>
<%= f.text_field :description %>
<%= f.label :typeof %>
<%= f.text_field :typeof %>
</div>
<%= f.fields_for :levels do |builder| %>
<%= render 'level_fields', f: builder %>
<% end %>
<%= link_to_add_fields "add level", f, :levels %>
<%= f.submit "Save", class: "btn btn-large btn-primary save" %>
<% end %>
</div>
</div>