title: Destroy method not firing to destroy nested resource in complex form
body: <p>I am running Rails 3.0.3 with Paperclip 2.3.8. I have two models, call them "Post" and "Image". Image is an object containing a Paperclip image file to dynamically add images to Posts. Image belongs to Post, and Post has many Images.</p>
  
  <p>Post Model:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
   has_many :images
   accepts_nested_attributes_for :images, :reject_if =&gt; lambda { |a| a[:image].blank? },  :allow_destroy =&gt; true
  end
  </code></pre>
  
  <p>Image Model:</p>
  
  <pre><code>class Image &lt; ActiveRecord::Base
   belongs_to :post
   has_attached_file :image,
        :styles =&gt; {
        :thumb=&gt; "100x100#",
        :small  =&gt; "300x300&gt;" }
  end
  </code></pre>
  
  <p>I have a form in which I would like to dynamically add and remove images. If the image is a new image being uploaded I would like to show a file_field; otherwise if the image already exists I would like to display the image and a remove link. I followed Ryan Bates' Railscasts on Nested Forms. Adding images dynamically is working, but the call to _destory is not firing. The post contains "_destroy"=>"1", but after the HTTP Post event the image with id 7 still exists. Here is an excerpt from the HTTP Post:</p>
  
  <pre><code>"images_attributes"=&gt;{
    "0"=&gt;{"id"=&gt;"7", "_destroy"=&gt;"1"}, 
    "1"=&gt;{"id"=&gt;"8", "_destroy"=&gt;"false"}, 
    "2"=&gt;{"id"=&gt;"9", "_destroy"=&gt;"false"}, 
    "3"=&gt;{"id"=&gt;"10", "_destroy"=&gt;"false"}}
  </code></pre>
  
  <p>Here is what the form looks like:</p>
  
  <pre><code>&lt;%= form_for @post, :html =&gt; { :multipart =&gt; true } do |f| %&gt;
   &lt;%= f.label :images, 'Images' %&gt;&lt;br /&gt;
   &lt;div class="field"&gt;
    &lt;%= f.fields_for :images do |s| %&gt;
     &lt;%= render 'image_fields', :f =&gt; s %&gt;
    &lt;% end%&gt;
   &lt;/div&gt; 
   &lt;div class="field"&gt;
    &lt;%= link_to_add_fields "Add Image", f, :images %&gt;
   &lt;/div&gt; 
   &lt;div class="actions"&gt;
    &lt;%= f.submit %&gt;
   &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>_image_fields:</p>
  
  <pre><code>&lt;div class="fields"&gt;
   &lt;% if !f.object.new_record? %&gt;
    &lt;%= image_tag f.object.image.url %&gt;
   &lt;% else %&gt;
    &amp;nbsp; &lt;%= f.file_field :image%&gt;
   &lt;% end %&gt;
   &lt;%= link_to_remove_fields "remove", f %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Javascript Functions:</p>
  
  <pre><code>function remove_fields(link){
   $(link).previous("input[type=hidden]").value = "1";
   $(link).up(".fields").hide();
  }
  
  function add_fields(link, association, content) {
   var new_id = new Date().getTime();
   var regexp = new RegExp("new_" + association, "g")
   $(link).up().insert({
    before: content.replace(regexp, new_id)
   });
  }
  </code></pre>
  
  <p>Helper Functions:</p>
  
  <pre><code>def link_to_remove_fields(name, f)
      f.hidden_field(:_destroy) +
      link_to_function(name, "remove_fields(this)")
  end
  
  def link_to_add_fields(name, f, association)
   new_object = f.object.class.reflect_on_association(association).klass.new
   fields = f.fields_for(association, new_object, :child_index =&gt; "new_#{association}") do |builder|
    render(association.to_s.singularize + "_fields", :f =&gt; builder)
   end
   link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")
  end
  </code></pre>
  
  <p>As I mentioned above I am able to add images. Clicking the "Add Image" link adds a file field to the form and I can add multiple images successfully. Clicking the "remove" link by an image removes the link and the image from the view - but as I said it is not deleted on Post event.</p>
  
  <p>Thank you in advanced; I appreciate anyone taking time to help me find a solution.</p>
  
  <p>Edit:</p>
  
  <p>--Solution--</p>
  
  <p>In the Post Controller added ".includes(:images)" to the find in the update method:</p>
  
  <pre><code>def update
   @post = Post.includes(:images).find(params[:id])
  
   respond_to do |format|
     if @post.update_attributes(params[:post])
       format.html { redirect_to(@post, :notice =&gt; 'Post was successfully updated.') }
       format.xml  { head :ok }
     else
       format.html { render :action =&gt; "edit" }
       format.xml  { render :xml =&gt; @post.errors, :status =&gt; :unprocessable_entity }
     end
   end
  end
  </code></pre>