title: Rails remote delete and update view through Ajax
body: <p>In the past, whenever I wanted to update a part of my view through Ajax, I've done the following:</p>
  
  <ol>
  <li>create a partial out of the part I want to update and give it a unique ID, say <code>#tracks</code></li>
  <li>create a special action in the controller for that Ajax call, say <code>remove_track</code> that updates all the values, etc. and add <code>format.js</code></li>
  <li>create a new JS file with the same name as the action so Rails calls it automatically <code>remove_track.js.erb</code> which contains something like: <code>$('#tracks').html("&lt;%=j render 'cds/show_tracks' %&gt;");</code></li>
  <li>set <code>remote: true</code> in the link that calls this action.</li>
  </ol>
  
  <p>All this is fine, but now I am trying to delete and update a common <code>index</code> view using the regular <code>destroy</code> method for flexibility, meaning I can call this method either through Ajax or normally. I figured it's such a common thing to do that there has to be a better way than all of the above. </p>
  
  <p>I can get the destroy method to call my <code>destroy.js.erb</code> file by simply putting this into the controller: </p>
  
  <pre><code>  format.js { layout: false }
  </code></pre>
  
  <p>and of course setting <code>remote: true</code> on the link. </p>
  
  <p>what I cannot do is get the view to refresh. The table I want to refresh is encased in a div with a unique ID, but since it's not a partial, it refuses to refresh the content. Maybe I'm missing something. </p>
  
  <p>Am I doomed to have to create a partial and refresh it with the method above or is there a more magical way of doing it (other than using Turbolinks)?</p>
  
  <p>Thanks.</p>
  
  <p><strong>PS</strong>
  Also, I just noticed this has the added disadvantage that I cannot pass the rest of the params to the destroy method since it only passes the object ID to destroy using the regular CRUD routes. If I try to use <code>platform(action: destroy)</code> or <code>platform(method: delete)</code> I get an error:</p>
  
  <pre><code>No route matches {:action=&gt;"destroy", :controller=&gt;"platforms"}
  </code></pre>
  
  <p>Which means I have to create a new route if I want to pass those parameters...</p>
  
  <p>Yet another disadvantage to all this is that I'm repeading all the logic for searches and sorting that I have in the index method again in the destroy method. I am certain this is <strong>definitely not</strong> the way to do it. </p>