title: link_to remote=>true not updating with ajax
body: <p>Using rails3 and prototype (rails.js)</p>
  
  <p>I have a simple list of products with edit and delete links as images.
  When deleting a product, the list is not updated. Refreshing the page shows that the product has indeed been deleted.</p>
  
  <p>/app/views/products/list.rhtml</p>
  
  <pre><code>&lt;div id="product_list"&gt;
    &lt;%= render :partial =&gt; 'list'  %&gt; 
  &lt;/div&gt;
  </code></pre>
  
  <p>/app/views/products/_list.rhtml</p>
  
  <pre><code>&lt;%= link_to image_tag("delete.png"), { :controller =&gt; 'products', :action =&gt; 'destroy', :id =&gt; product }, :method =&gt; :delete, :confirm =&gt; "Are you sure?", :remote =&gt; true %&gt;
  </code></pre>
  
  <p>/app/controllers/products.rb</p>
  
  <pre><code>  def destroy
      Product.find(params[:id]).destroy
      @products = Product.all
    end
  </code></pre>
  
  <p>/app/views/products/destroy.rjs (not sure what to do with that...)</p>
  
  <pre><code>$(document).ready(function() {
      $("#product_list").html("&lt;%= escape_javascript( render(:partial =&gt; "list") ) %&gt;");
  });
  </code></pre>
  
  <p>So the remote link seems to work fine.
  I'm not sure how to use the ajax callback to update #product_list</p>
  
  <p>I tried to put the following in the head of the page:</p>
  
  <pre><code>$(document).ready(function(){
    $('#product_list').bind("ajax:success", function(evt, data, status, xhr){
        alert('hello');
      })
  });
  </code></pre>
  
  <p>But it's not executed (that's probably not a valid code for prototype) and I wouldn't know anyway what code to put inside so that my list gets updated after destroying a product</p>
  
  <p>Any help (other than "use jQuery") is greatly appreciated!</p>
  
  <p><strong>EDIT</strong>: Here is the server log for the delete action (after I moved the javascript above to destroy.js.erb)</p>
  
  <pre><code>Started POST "/products/destroy/3" for 127.0.0.1 at .....
  Processing by ProductsController#destroy as JS
  Parameters: {"_"=&gt;"", "id"=&gt;"3"}
  [1m[36mProduct Load (0.0ms)[0m  [1mSELECT `products`.* FROM `products` WHERE (`products`.`id` = 3) LIMIT 1[0m
    [1m[35mSQL (0.0ms)[0m  BEGIN
    [1m[36mSQL (0.0ms)[0m  [1mDELETE FROM `products` WHERE (`products`.`id` = 3)[0m
    [1m[35mSQL (78.1ms)[0m  COMMIT
    [1m[36mProduct Load (0.0ms)[0m  [1mSELECT `products`.* FROM `products`[0m
  Rendered products/destroy.js.erb within layouts/standard (31.2ms)
  Completed 200 OK in 312ms (Views: 62.5ms | ActiveRecord: 78.1ms)
  </code></pre>
  
  <p><em>Processing by ProductsController#destroy as JS</em> so the remote link works</p>
  
  <p><em>[36mProduct Load (0.0ms)[0m  [1mSELECT <code>products</code>.</em> FROM <code>products</code>* The @products = Product.all is executed</p>
  
  <p><em>Rendered products/destroy.js.erb within layouts/standard</em> the javascript fie is rendered</p>
  
  <p>So now I guess it's a problem with the javascript code:</p>
  
  <p>$(document).ready(function() {
      $("#product_list").html("&lt;%= escape_javascript( render(:partial => "list") ) %>");
  });</p>
  
  <p>Is that kind of code supported by prototype? I don't use jQuery...</p>