Search code examples
ruby-on-railsinternet-explorerscriptaculousrjs

RJS error: [object Error] in IE 8 on RJS response from rails/scriptaculous


I have a controller with:

render :update do |page|
  page.replace_html 'some_id', :partial => 'some_partial'
end

It works fine in firefox, but IE throws an "RJS Error: [Object error]"

Looking at the generated javascript, it look like this:

Element.update("some_id", "\u003Cselect id=\"some_other_id\" name=\"some_name[]\"\u003E\u003Coption value=\"-1\"\u003E\u0026lt; Default option \u0026gt;\u003C/option\u003E\n\u003Coption value=\"1\" selected=\"selected\"\u003E Some option \u003C/option\u003E\u003C/select\u003E\n");

But even trying with Element.update("some_id", "hello world") fails in IE.
Replacing with an empty string works, though.

Looking into the Element.update function:

update: function(element, content) {
  element = $(element);
  if (content && content.toElement) content = content.toElement();
  if (Object.isElement(content)) return element.update().insert(content);
  content = Object.toHTML(content);
  element.innerHTML = content.stripScripts();
  content.evalScripts.bind(content).defer();
  return element;
}

It seems that element.innerHTML = content.stripScripts(); is causing some trouble, throwing an "Unknown runtime error" no matter what I feed it, except the empty string.

I know that IE will complain if trying to put a block-level element inside an inline element, but this is not the case.

I'm on rails 2.3.11, scriptaculous 1.8.1 and prototype 1.6.0.3

I'm quite lost - any hints is welcome.


Solution

  • Try page.replace instead of page.replace_html. It looks like you may be updating a select lists options with another select list. Another way would be to just replace the options using options_for_select to render the options tags.