title: Rails nested form using file_field element
body: <p>I am using code found at Railscast 197 to create nested forms using jQuery. The challenge I am facing is that the nested model uses a file_field element, and because of this when looking at the <strong>edit</strong> view I just see a list of empty file_field elements. Is there a way I can tell rails to display something else (like a disabled text_field) when the user is viewing the <strong>edit</strong> view, but a file_field when viewing the <strong>new</strong> view?</p>
  
  <p>This is the partial I am using:</p>
  
  <pre><code>&lt;div class="fields"&gt;
      &lt;p&gt;
          &lt;%= f.label :document_type %&gt;
          &lt;%= f.select :document_type, XmlDocument::SOURCES %&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;%= f.file_field :inputfile, :class =&gt; 'text' %&gt;
          &lt;%= f.hidden_field(:_delete) + link_to('Remove', "javascript:void(0)", :class =&gt; "remove_child remove-xmldoc") %&gt;
      &lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And this is the jQuery that adds it (modified slightly from the Railscast to add an effect when displaying the partial):</p>
  
  <pre><code>$('form a.add_child').click(function() {
      var assoc   = $(this).attr('data-association');
      var content = $('#' + assoc + '_fields_template').html();
      var regexp  = new RegExp('new_' + assoc, 'g');
      var new_id  = new Date().getTime();
  
      var newElements = jQuery(content.replace(regexp, new_id)).hide();
      $(this).parent().before(newElements).prev().slideFadeToggle();
  
      return false;
  });
  </code></pre>
  
  <p>But within my _form partial I have:</p>
  
  <pre><code>&lt;div id="xml_documents"&gt;
      &lt;%= label_tag 'XML Documents' %&gt;
      &lt;% form.fields_for :xml_documents do |stream_xml_document_form| %&gt;
      &lt;%= render :partial =&gt; "xml_document", :locals =&gt; {:f =&gt; stream_xml_document_form} %&gt;
      &lt;% end %&gt;
  
      &lt;p&gt;&lt;%= link_to('Add XML Document', "javascript:void(0)", :class =&gt; "add_child add-xmldoc", :"data-association" =&gt; :xml_documents) %&gt;&lt;/p&gt;
      &lt;%= new_child_fields_template(form, :xml_documents) %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>which is what adds the partial, I'm guessing that somewhere in here I need to have a conditional of some sort that tells rails to render a different partial if the object is already created or or not.. Anyone have any ideas as to how I can accomplish this?</p>