Link_to_remote gives a javascript error

I'm using this code in controller when updating the page:

    render :update do |page|         ...         for p in @cat_photos           page << "$('#flyingCats').html($(this).html() + '" + link_to_remote(image_tag(p.image.url(:thumb)),              {:url => {:controller => "photos" ,:action => :refresh_image,                      :id => p.id}, :method => :get}, { :href => "#" }) + "');"         end        ...     end

And, though, I'm using exactly this code in the other part of app and it works, i get a strange js error in FireBug:

"missing ) after argument list [Break on this error] $('#flyingCats').html($(this).html() + '...h_image?id=11'}); return false;"><img al..."

I'm using this code in controller when updating the page:

render :update do |page|
    \.\.\.
    for p in @cat\_photos
      page &lt;&lt; &quot;$\(&#39;\#flyingCats&#39;\)\.html\($\(this\)\.html\(\) \+ &#39;&quot; \+

link_to_remote(image_tag(p.image.url(:thumb)),

Have you looked at what this expands to ? I wouldn't be surprised if what the link_to_remote expands to included a quote mark which would screw your stuff up.

Fred

Bug fixed by putting link_to_remote in escape_javascript function:

          page << "$('#flyingCats').html($(this).html() + '" + escape_javascript(link_to_remote(image_tag(p.image.url(:thumb)), {:url => {:controller => 'photos', :action => :refresh_image, :id => p.id}, :method => :get})) + "');"

I hope my solution would be useful.