<%= nested_form_for(@template, :html => {:multipart => true}) do |f| %>
  <% if @template.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@template.errors.count, "error") %> prohibited this template from being saved:</h2>

      <ul>
      <% @template.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :author %><br>
    <%= f.text_field :author %>
  </div>

  <p>
  <label>Thumbnail</label>
    <%= f.file_field :thumbnail %>
    <%= f.hidden_field :thumbnail_cache %>
  </p>

  <%= f.fields_for :previews do |p| %>
   <%= p.file_field :image %>
   <%= p.hidden_field :image_cache %>
   <%= p.link_to_remove "Remove this file" %>
  <% end %>
  <p><%= f.link_to_add "Add a file", :previews %></p>

  <p>
  <label>Template</label>
    <%= f.file_field :template %>
    <%= f.hidden_field :template_cache %>
  </p>
 
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
