# Replace\_html and Prototype

**URL:** <https://www.ruby-forum.com/t/replace-html-and-prototype/83713>\
**Category:** Rails\
**Created:** [January 29, 2007, 5:01am UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713 "2007-01-29T05:01:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 29, 2007, 5:01am UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713/1 "2007-01-29T05:01:41Z")

</div>

'm trying to change over from Rails 1.1.6 to 1.2.1 and have discovered  
that either something is wrong with Prototype of else something has  
changed that I am not aware of and cannot find documentation on. (I  
just joined this group, so if this has already been cussed and  
discussed here or in another list then please point me in the right  
direction.)

I posted this to the Spinoffs group since it seemed to be more focused  
on javascript, but didn’t get any replys. I still haven’t been able to  
figure out what is going on so I’m reposting it here:

===Origional Message===

I am trying to use the “replace\_html” feature, and instead of  
prototype  
processing the generated javascript, I get a big load of “try  
{Element.update( …lots of javascript garbage… ) throw e }” dumped  
onto my screen in place of where the updated html should be.

I encountered the same problem when I tried to work around it by using  
“replace” to swap out the whole element with updated innerHTML. The  
only way I could get around this problem was to use “replace” while  
changing the element id every time. (Which results in more code than  
should be necessary)

Basically, whenever I try to update an element, the javascript doesn’t  
get picked up by prototype unless the id of the target element gets  
changed in the process.

Is this a bug or am I completely missing something here? I’ve only  
been  
using Rails for a couple months now, so I’m a bit new at this…

Thanks,  
-Reuben

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 29, 2007, 6:10am UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713/2 "2007-01-29T06:10:45Z")

</div>

Hi, after updating to 1.2.1, did you run ‘rake rails:update’ after  
changing the version to 1.2.1 in the environment.rb?

-Conrad

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 3, 2007, 3:20am UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713/3 "2007-02-03T03:20:51Z")

</div>

Sorry for the late reply, I’ve been gone.

Yes, I had already done that. There were finally some replies to the  
origional post for this problem that I posted to the Spinoffs list,  
and apparently I’m not the only one running into this problem.

-Reuben

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 3, 2007, 3:45am UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713/4 "2007-02-03T03:45:52Z")

</div>

I strongly suspect your using the :update option on your remote  
call???

I commented on this in another post, here is my comment from that  
post:

> on main.rhtml, I have:  
> \<%= link\_to\_remote(‘add’, :url=\>{:action=\>‘openAdd’},  
> :update=\>‘addZone’)-%\> # don’t use :update for rjs calls

Don’t use the :update option with rjs calls. That constructs an  
Ajax.Updater prototype object instead of the Ajax.Request object you  
need for rjs calls.

On the other hand, if you only need to update one html element, I’d  
leave the :update option and just return a regular partial template,  
pretty sure it’s considerably faster.

Good Luck,  
Tim

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 3, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713/5 "2007-02-03T17:57:52Z")

</div>

Yes, I was using the :update option. However, I had already changed it  
to the new in-line format using

```
update_page do |page|
  ...
end

```

Do I need to go back to using and RJS template if I get rid of  
the :update option?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 3, 2007, 8:26pm UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713/6 "2007-02-03T20:26:10Z")

</div>

The in-line format is exactly the same as using a template, it just  
gives you a way to in-line 🙂 instead of having to create a new file  
when you only need to write a couple lines.

If you use the :update option simply return regular old text/html  
(e.g. a partial). Without the :update option you need to return  
javascript which is where rjs, including the in-line form, comes in.

Tim

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 6, 2007, 3:38am UTC](https://www.ruby-forum.com/t/replace-html-and-prototype/83713/7 "2007-02-06T03:38:49Z")

</div>

That fixed my problem. Thanks for the help.  
-Reuben
