I''m using RedCloth and am trying to update a div (id=''page_content'') from an ajax link. The problem is that when the element is updated it inserts the content twice and contains all kinds of ajax code, newline and tab characters with the content. Here is the link: link_to_remote "Exhibitions", update => ''page_content'', :url => { :controller => ''pages'', :action => ''ajax_link'', :page_name => "exhibitions" }, :loading => "Element.show(''ajax-loader'')", :loaded => "Element.hide(''ajax-loader'')" the ajax_link action is: def ajax_link @page = Page.find_by_page_name(params[:page_name]) respond_to do |format| format.js { } format.html { render :action => ''show'' } end end and the ajax_link.rjs is: page.replace_html :page_content, :partial => ''page_content'', :object => @page Although if I change the ajax_link action to the following the div is updated correctly: def ajax_link @page = Page.find_by_page_name(params[:page_name]) respond_to do |format| format.js { render :text => "#{RedCloth.new (@page.page_content).to_html}" } format.html { render :action => ''show'' } end end Thanks for any help, Stu --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you''re using link_to_remote to call an action which has an RJS template, you need to remove the "update => ''page_content''," argument in link_to_remote. If you specify :update, link_to_remote expects to get back some HTML with which to replace that element of your DOM. When you leave that off, link_to_remote looks for JavaScript (which is what RJS returns) to then execute on the client-side. That executed JavaScript then produces the HTML and decides where to put it. Check out this thread for a (probably) more lucid explanation: http://www.ruby-forum.com/topic/95288 On Sat, Jan 17, 2009 at 9:56 PM, shenry <stuarthenry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m using RedCloth and am trying to update a div (id=''page_content'') > from an ajax link. The problem is that when the element is updated it > inserts the content twice and contains all kinds of ajax code, newline > and tab characters with the content. Here is the link: > > link_to_remote "Exhibitions", update => ''page_content'', :url => > { :controller => ''pages'', :action => ''ajax_link'', :page_name => > "exhibitions" }, :loading => "Element.show(''ajax-loader'')", :loaded => > "Element.hide(''ajax-loader'')" > > the ajax_link action is: > > def ajax_link > @page = Page.find_by_page_name(params[:page_name]) > respond_to do |format| > format.js { } > format.html { render :action => ''show'' } > end > end > > and the ajax_link.rjs is: > > page.replace_html :page_content, :partial => ''page_content'', :object > => @page > > Although if I change the ajax_link action to the following the div is > updated correctly: > > def ajax_link > @page = Page.find_by_page_name(params[:page_name]) > respond_to do |format| > format.js { render :text => "#{RedCloth.new > (@page.page_content).to_html}" } > format.html { render :action => ''show'' } > end > end > > Thanks for any help, > > Stu > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the help Ryan, works great. On Jan 18, 12:00 am, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote:> If you''re using link_to_remote to call an action which has an RJS template, > you need to remove the "update => ''page_content''," argument in > link_to_remote. If you specify :update, link_to_remote expects to get back > some HTML with which to replace that element of your DOM. > > When you leave that off, link_to_remote looks for JavaScript (which is what > RJS returns) to then execute on the client-side. That executed JavaScript > then produces the HTML and decides where to put it. > > Check out this thread for a (probably) more lucid explanation: > > http://www.ruby-forum.com/topic/95288 > > On Sat, Jan 17, 2009 at 9:56 PM, shenry <stuarthe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''m using RedCloth and am trying to update a div (id=''page_content'') > > from an ajax link. The problem is that when the element is updated it > > inserts the content twice and contains all kinds of ajax code, newline > > and tab characters with the content. Here is the link: > > > link_to_remote "Exhibitions", update => ''page_content'', :url => > > { :controller => ''pages'', :action => ''ajax_link'', :page_name => > > "exhibitions" }, :loading => "Element.show(''ajax-loader'')", :loaded => > > "Element.hide(''ajax-loader'')" > > > the ajax_link action is: > > > def ajax_link > > @page = Page.find_by_page_name(params[:page_name]) > > respond_to do |format| > > format.js { } > > format.html { render :action => ''show'' } > > end > > end > > > and the ajax_link.rjs is: > > > page.replace_html :page_content, :partial => ''page_content'', :object > > => @page > > > Although if I change the ajax_link action to the following the div is > > updated correctly: > > > def ajax_link > > @page = Page.find_by_page_name(params[:page_name]) > > respond_to do |format| > > format.js { render :text => "#{RedCloth.new > > (@page.page_content).to_html}" } > > format.html { render :action => ''show'' } > > end > > end > > > Thanks for any help, > > > Stu--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---