Forum: Ruby on Rails in_place_editor consumes html tags?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aab990aa874b0d2504431f8863729672?d=identicon&s=25 Jon F. (jonf)
on 2006-06-12 22:57
I've got a bog-standard view which displays textilized data. In the same
view, I have an in_place_editor which uses load_text_url to bring in
non-textilized data when editing.

Now, if I have html tags in the data loaded from load_text_url, they
appear to go missing. I can see the tags in the output from my
controller method using the console, but the tags are not shown in the
in_place_editor textarea and -- most importantly -- appear to actually
have been stripped from the text sent by the controller method (I've run
it through the DOM inspector in Firefox to double-check).

Oddly, if I disable load_text_url for the in_place_editor, html tags
from the rendered page are shown inside the editing textarea without
trouble. So, it looks like something is occurring in load_text_url.

Before I go digging through the javascript, could someone tell me if
missing something completely obvious here?

***

My controller method for load_text_url:

def get_data
   @page = Page.find(params[:id])
   render :text => @page.data
end

***

My view code:

<div id="data">
   <%= textilize( @page.data.blank? ? 'No data.' : @page.data ) %>
</div>

<%= in_place_editor "data",
	:load_text_url => url_for( :controller => 'pages', :action =>
'get_data', :id => @page.id ),
        :url => pages_url( :action => 'update_attribute', :id =>
@page.id, :target => 'data' ),
        :rows => 25, :cols => 80 %>

***

My sample data:

h1. Sample method

The following is a sample method...

<code>
def load
   @foo = Baz.find(:first)
   return @foo.bar
end
</code>
Aab990aa874b0d2504431f8863729672?d=identicon&s=25 Jon F. (jonf)
on 2006-06-13 01:38
Looks like tags are being stripped when the text is finally loaded via
load_text_url:

From controls.js:

  onLoadedExternalText: function(transport) {
    Element.removeClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = false;
    this.editField.value = transport.responseText.stripTags();
  }

I'm curious why this is done. The tags should be rendered as...well,
tags...in the textarea. They should not be rendered as html and any
javascript should not be executed. So why are tags removed? Anyone have
some insight?

This makes it rather difficult to allow in place editing of both html
and RedCloth/Textile markup, right?
Aab990aa874b0d2504431f8863729672?d=identicon&s=25 Jon F. (jonf)
on 2006-06-13 02:36
Not an ideal solution, but I've gotten around this by placing the
following in my application.js:

Ajax.InPlaceEditor.prototype.onLoadedExternalText = function(transport)
{
    Element.removeClassName(this.form, this.options.loadingClassName);
    this.editField.disabled = false;
    this.editField.value = transport.responseText;
}

This overrides the default behavior (as long as application.js comes
after controls.js in the include order in the layout).
This topic is locked and can not be replied to.