title: Why is my dependent destroy not working in Rails?
body: <p>Thanks for your help with this! I have many newsavedmaps, and each can have multiple waypoints. The waypoints table connects to the newsavedmaps id with a field, "newsavedmap_id." I am new to Rails (using Rails 2), and I'm having trouble with a destroy feature. Essentially, if a user gets rid of a newsavedmap, I also want to eliminate the waypoints.</p>
  
  <p><strong>newsavedmap.rb</strong></p>
  
  <pre><code>    has_many :waypoints, :dependent =&gt; :destroy
  </code></pre>
  
  <p><strong>waypoint.rb</strong></p>
  
  <pre><code>    belongs_to :newsavedmap
  </code></pre>
  
  <p><strong>newsavedmap controller (I think this is the problem)</strong></p>
  
  <pre><code>    def destroy
      @newsavedmap = Newsavedmap.find(params[:id])
      @waypoint = Waypoint.find(params[:id])
      @newsavedmap.destroy
      @waypoint.destroy
  
      respond_to do |format|
      format.html { redirect_to "/CODE" }
      format.xml  { head :ok }
      end
      end
  </code></pre>
  
  <p>I also have a view, newmaps.html.erb. A user sees his newsavedmap on the page, and he can click a link:</p>
  
  <pre><code>    &lt;a href="/newsavedmaps/&lt;%= newsavedmap.id %&gt;" class="newremovemap"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>When he does, this is the javascript that kicks in:</p>
  
  <pre><code>    $('.newremovemap').click(function(){
          if (confirm('Are you sure you want to remove this map?')) {
              var mappage = $(this).closest('.wholemap'); 
              var map = $(this).parent();
              $.post(this.href, { _method: "delete", authenticity_token: $('#auth_token').val() }, function(){
                  mappage.fadeOut();
  
              });
          };
          return false;
      })
  </code></pre>
  
  <p>Now, when I click the link, the alert message repeats many times, but the records are not removed. The error code is ActiveRecord::RecordNotFound (Couldn't find Waypoint without an ID). I've tried applying links like this to the problem (
  <a href="https://stackoverflow.com/questions/18044424/rails-dependent-destroy-error">Rails dependent destroy error</a>), but I can't seem to find a solution. </p>