title: rails link_to :remote from within ajax-loaded content
body: <p>Hey everyone, I'm working on an application and I'm having difficulty with the new Rails 3 link_to. Here's the situation - I have two divs on my "home" page, and each div is populated at document.load with ajax. This works as expected.</p>
  
  <p>In the content of the pages I'm loading into these divs, I want to use the link_to... :remote => true functionality. The source renders as expected with the data-remote="true" tag, but when I click on the links, they're completely ignored (the link is treated as a regular hyperlink). </p>
  
  <p>I've written .rjs files that handle everything properly (because they work when hard-coded), so that's not the issue. </p>
  
  <p>Here's the html source for the ajax-loaded content:</p>
  
  <pre><code>&lt;div&gt;
    &lt;a href="/cart/add/2" data-remote="true"&gt;Link A&lt;/a&gt;
    &lt;a href="/cart/add/1" data-remote="true"&gt;Link B&lt;/a&gt; 
  &lt;/div&gt;
  </code></pre>
  
  <p>Clicking on one of those links when normally embedded into the page causes my shopping cart to update correctly... however, when I dynamically load this content into the page with AJAX, the link just follows and ignores the data-remote="true"... </p>
  
  <p>Originally I thought it had something to do with prototype not loading correctly in the AJAX stuff, but I've checked all of that and it doesn't change a thing...</p>
  
  <p>I'm really confused... Does anybody have a thought on this?</p>
  
  <pre><code># add method of controller
  def add
    product = Product.find_by_id(params[:product_id])
    params[:quantity] ||= 1
    params[:price] ||= product.price
  
    unless product.nil?
      @line = session[:cart].purchase_lines.select {|l| l.product_id == product.id}.first
      unless @line.nil?
        @line.quantity = (@line.quantity + params[:quantity].to_i)
      else # create a new purchase_line in the cart
        @line = session[:cart].purchase_lines.build({ :product_id =&gt; product.id, :price =&gt; params[:price], :quantity =&gt; params[:quantity].to_i })
      end
    else
      flash[:error] = "Unable to add the selected product"
    end
  end  
  </code></pre>
  
  <p>and my rjs</p>
  
  <pre><code># add.rjs
  page.if page['product_' &lt;&lt; @line.product_id.to_s] do
    page.replace 'product_' &lt;&lt; @line.product_id.to_s, :partial =&gt; 'line'
  page.else
    page.insert_html :bottom, 'cart', :partial =&gt; 'line'
  end
  
  page.replace_html 'sub_total', number_to_currency(session[:cart].sub_total, :unit =&gt; '$')
  page.replace_html 'tax', number_to_currency(session[:cart].tax, :unit =&gt; '$')
  page.replace_html 'total', number_to_currency(session[:cart].sub_total+session[:cart].tax, :unit =&gt; '$')
  page.visual_effect :highlight, 'product_' &lt;&lt; @line.product_id.to_s, :duration =&gt; 1
  </code></pre>