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..."
On Jun 30, 4:40 am, Colorblind <colorblin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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)),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> {: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..."
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.
Colorblind wrote:> Bug fixed by putting link_to_remote in escape_javascript function:[...] Glad to hear it! <soapbox> Now extract the JS code from your view into a separate file so that you don''t have to use escape_javascript. (JS doesn''t belong in HTML.) </soapbox> Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.