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