title: Carrierwave file delete
body: <p>Again I need your help. Now I need to understand how I can delete with Carrierwave uploaded files (in my case - images).</p>
  
  <p><em><strong>models/attachment.rb :</em></strong></p>
  
  <pre><code>class Attachment &lt; ActiveRecord::Base
    belongs_to :attachable, :polymorphic =&gt; true
    attr_accessible :file, :file
    mount_uploader :file, FileUploader
  end
  </code></pre>
  
  <p><em><strong>models/post.rb :</em></strong></p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    attr_accessible :content, :title, :attachments_attributes, :_destroy
    has_many :attachments, :as =&gt; :attachable
    accepts_nested_attributes_for :attachments
  end
  </code></pre>
  
  <p>*<strong>views/posts/_form.html.erb :*</strong></p>
  
  <pre><code>&lt;%= nested_form_for @post, :html=&gt;{:multipart =&gt; true } do |f| %&gt;
    &lt;% if @post.errors.any? %&gt;
      &lt;div id="error_explanation"&gt;
        &lt;h2&gt;&lt;%= pluralize(@post.errors.count, "error") %&gt; prohibited this post from being saved:&lt;/h2&gt;
  
        &lt;ul&gt;
        &lt;% @post.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;div id="field"&gt;
      &lt;%= f.label :Nosaukums %&gt;:&lt;br /&gt;&lt;br /&gt;
      &lt;%= f.text_field :title %&gt;&lt;br /&gt;&lt;br /&gt;
    &lt;/div&gt;
    &lt;div id="field"&gt;
      &lt;%= f.label :Raksts %&gt;:&lt;br /&gt;&lt;br /&gt;
      &lt;%= f.text_area :content %&gt;&lt;br /&gt;&lt;br /&gt;
    &lt;/div&gt;
  
      &lt;%= f.fields_for :attachments do |attachment| %&gt;
      &lt;% if attachment.object.new_record? %&gt;
        &lt;%= attachment.file_field :file %&gt;
  
      &lt;% else %&gt;
        &lt;%= image_tag(attachment.object.file.url) %&gt;
        &lt;%= f.check_box :_destroy %&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  
  
      &lt;%= f.submit "Publicēt", :id =&gt; "button-link" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>When I am trying to delete previous uploaded file I have this error:</p>
  
  <pre><code>unknown attribute: _destroy
  </code></pre>
  
  <p>Maybe there is problem because I have multiple file uploads not only one.</p>