2013-10-07 35 views
0

HI im使用nested_forms for rails。 https://github.com/ryanb/nested_form如何刪除默認的初始第二個嵌套字段?

工作很好我的問題是,每次用戶編輯他的信息時,默認情況下會添加一個新字段,我需要添加新字段,直到用戶在鏈接中添加「添加更多」創業板,但文件的使用dosent說這事..

這裏是我的代碼:

<%= f.fields_for :citizens do |citizen_form| %> 

     <div> 
      <%= citizen_form.label :citizen, t('generales.citizen') %> 
      <%= citizen_form.select :country_id , Country.all.collect {|p| [ t("generales."+p.iso), p.id ] }, { :include_blank => true } , { :class => 'pca33' } %> 
      <div id="delerr"><%= citizen_form.link_to_remove t('generales.delete') %></div> 
     </div> 

     <% end %> 

     <%= f.link_to_add t('generales.add'), :citizens %> 

回答

0

好吧,我找到了答案..

下面是做到這一點的方式。

@project.tasks.build unless @project.tasks.any? 

在我的情況是什麼。

@player.citizens.build unless @player.citizens.any? 

希望它可以幫助別人。

相關問題