ユーザーがフォームフィールドを動的に追加および削除できるようにするnested_form gemを使用しています。正常に動作していますが、ユーザーが最初の file_field を削除できないようにして、ユーザーが追加したフィールドの場合にのみ「削除」リンクを表示できるようにしたいと考えています。私の「_form」と「_photo_fields」のパーシャルは以下のとおりです。解決策は、「このフィールドがページ上のそのタイプの最初のフィールドでない場合は、「削除」リンクを表示する」のようなことだと思いますが、それを達成する方法がわかりません。あなたが提供できる洞察をありがとう。
_form.html.erb:
<%= simple_nested_form_for @service_offering do |f|%>
... Other Fields ...
<%= f.fields_for :photos do |builder| %>
<%= render 'photo_fields', :f => builder %>
<%end%>
<%= f.button :submit %>
<p><%= f.link_to_add "Add Photo", :photos %></p>
_photo_fields.html.erb:
<% if f.object.new_record? %>
<%= f.label :photo %>
<%= f.file_field :photo %>
# This is where I want to drop that if statement, but I am not sure what it should be.
<%= f.link_to_remove "Remove" %>
#
<%end%>
<% unless f.object.new_record? %>
<%= link_to( image_tag(f.object.photo.url(:thumb))) %>
<%= f.check_box :_destroy %>
<%= f.label :_destroy, "Remove" %>
<%end%>