Topic: in_place_editor + :script=>true not evaluating JS

Hi,

With Rails 2.0.2 (prototype 1.6.0.1 and 1.6.0.2)

In my view I have

<span id='cd_<%=cd.id%>'><%= v %></span>
<%= in_place_editor "cd_#{cd.id}", :script=>true , :url=>{:action=> :edit_value,:controller=> 'custom_data',:id=> cd.id} %>

And in my RJS I have
page.alert "hello"
page.replace_html "cd_#{@cd.id}", 'TEST'

The alert works, but instead of evaluating the replace_html part, the in place editor changes its text to

try { alert("hello"); Element.update("cd_31", "TEST"); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('alert(\"hello\");\nElement.update(\"cd_31\", \"TEST\");'); throw e }

I tried replacing the *.js script.aculous files in public/javascripts with the ones from an earlier Rails project (prototype 1.5) and everything works as it should. Am I the only one with this problem ?

Last edited by henrijones2 (2008-02-07 13:10:26)

Re: in_place_editor + :script=>true not evaluating JS

I really need to get this working... No one can help ?

Re: in_place_editor + :script=>true not evaluating JS

I found the problem, and a workaround.

rails' "in_place_editor" doesn't let you specify htmlResponse for the underlying Ajax.InPlaceEditor call, which needs to be set to false.

I don't know why htmlResponse now defaults to false... Anyways, as can be read there http://www.pluitsolutions.com/2007/03/2 … alidation/ I fixed it by putting

  <script>
  Ajax.InPlaceEditor.DefaultOptions.htmlResponse = false;
  </script>

right after the inclusion of control.js

I find it hard to believe that something that important is now broken, and that no one has stumbled into it... Or my google-fu is not what I thought it was...

Re: in_place_editor + :script=>true not evaluating JS

Actually, changing this default breaks normal in_place_editor behavior...

I suggest adding this line in in_place_macros_helper.rb in the plugin's folder, instead of the solution above

js_options['htmlResponse'] = options[:html_response] if !options[:html_response].nil?

near the end of the in_place_editor() method, and passing :html_response=>false in your views when you call in_place_editor()

Re: in_place_editor + :script=>true not evaluating JS

I had to make a similar patch to in_place_editor but I did this instead:

js_options['htmlResponse'] = !options[:script] if options[:script]

That way I didn't have to change my templates.  See this ticket.

Also, I was restricting this to POST using a filter and had to also pass in

:options => "{method:'post'}"

to get THAT to work like it used to.