title: Rails: Destroy not working for nested attributes
body: <p>I have an application where the user can create a <code>gallery</code> to which he/she can attach some pictures. I use carrierwave for this purpose and it's structured as following.
  Each <code>gallery</code> has many <code>pictures</code> and each <code>picture</code> has 1 <code>image</code>.</p>
  
  <pre><code>class Gallery &lt; ActiveRecord::Base
      has_many :pictures, dependent: :destroy
      accepts_nested_attributes_for :pictures, allow_destroy: true;
  end
  class Picture &lt; ActiveRecord::Base
      belongs_to :gallery
      mount_uploader :image, ImageUploader
  end
  </code></pre>
  
  <p>The gallery and pictures are uploaded and edited in the following manner</p>
  
  <pre><code>&lt;ul&gt;
      &lt;%= f.fields_for :pictures do |builder| %&gt;
         &lt;li class="clearfix fields"&gt;
         &lt;% if p.object.image.length &gt; 1 %&gt;
             &lt;%= image_tag(p.object.image)  %&gt;
         &lt;% end %&gt;
         &lt;%= p.file_field :image %&gt;
         &lt;%= p.text_field :title %&gt;
         &lt;% if p.object.image.length &gt; 1 %&gt;
             &lt;br /&gt;
             &lt;%= p.hidden_field :_destroy %&gt;
             &lt;a href="#" class="delete-link"&gt;Remove picture&lt;/a&gt;
         &lt;% end %&gt;
         &lt;/li&gt;
      &lt;% end %&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>When the <code>delete-link</code> is clicked, the <code>_destroy</code> fields value is set to <code>true</code> (with javascript). This works just fine. I also permit the <code>_destroy</code> attribute in my strong parameters and I see it being passed to the <code>GalleriesController</code>.</p>
  
  <pre><code>def gallery_params
      params.require(:gallery).permit(:title, :synopsis, :thumb, pictures_attributes: [:image, :title, :id, :_destroy])
  end
  </code></pre>
  
  <p>But somehow the pictures are not being deleted. Any idea what more needs to be added, or what needs to be corrected?</p>
  
  <p>EDIT,
  the params that are being passed look like this</p>
  
  <pre><code>Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"lTad77QCH7hDcSaKm0EFI90KhY+nVwNS4jRNADC7DSR1ATxszDwlHefWNyNEdVqdqpuvEh9PkBFnoPIfnp9JKw==", "gallery"=&gt;{"title"=&gt;"new one", "synopsis"=&gt;"ssfjalsdj;fk", "pictures_attributes"=&gt;{"0"=&gt;{"title"=&gt;"portfolio", "_destroy"=&gt;"true", "id"=&gt;"4"}, "1"=&gt;{"title"=&gt;""}}, "thumb_cache"=&gt;""}, "commit"=&gt;"Update Gallery", "id"=&gt;"2"}
  </code></pre>
  
  <p>the controllers look like this</p>
  
  <pre><code>class GalleriesController &lt; ApplicationController
      def update
          @gallery.update(gallery_params)
          redirect_to(gallery_path(@gallery))
      end
  end
  class PicturesController &lt; ApplicationController
      def destroy
          @picture = Picture.find(params[:id])  
          @picture.destroy
      end
  end
  </code></pre>